Re: A job to update other jobs

2017-05-16 Thread 'Maciej Jaros' via Jenkins Users

Morgan Blackthorne (2017-05-12 20:05):
So I'm a little confused as to setting job to a value, but then 
referencing build.setDescription afterwards... or should that be 
job.setDescription?


// loop over jobs (possible also in Script Console)
for (item in hudson.model.Hudson.instance.items) {
  println("Saving " + item);
  item.save();
}

Do I need to save them all, or just the one I modified? Like job.save(); ?


I don't think you need to save jobs after doing something with them. 
That was just an example action in the loop. Just test your commands in 
the script console and see if it works. Make sure you you have backup of 
at least config.xml of your jobs ;-).


Regards,
Nux.

PS: I actually use this loop in our Jenklins installation. I do this to 
re-fresh configs after plugin updates. Doing `save` forces plugins to 
verfiy job config and possibly insert defaults.


--
You received this message because you are subscribed to the Google Groups "Jenkins 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/2e786696-48d8-87ca-7d1e-1b2c732bc70b%40mol.com.pl.
For more options, visit https://groups.google.com/d/optout.


Re: A job to update other jobs

2017-05-12 Thread Morgan Blackthorne


On Wednesday, May 10, 2017 at 4:23:26 AM UTC-7, maciej wrote:
>
> Morgan Blackthorne (2017-05-08 19:56):
>
> We're using Chef automation around configuring our Jenkins jobs. Basically 
> chef clones a git repo with the job XML files, and then tells Jenkins to 
> use them. 
>
> What we want to have is:
>
>1. One job to edit other jobs description to say "FROZEN by  
>at " or to remove the FROZEN line (basically a toggle) 
>2. Chef will then be updated to look at the job XML currently on the 
>Jenkins server 
>   1. If the description includes FROZEN, skip that job and leave it 
>   alone 
>   2. If the description does not include FROZEN, update the job from 
>   the XML file 
>
> I'm not really up to speed on Groovy, so what's the simplest way to 
> approach this? (I already know how to do the XML check for step 2, we can 
> just look at the XML over HTTP.)
>
>
> This should get you started...
>
> Install Groovy plugin 
> . Use Groovy 
> system step -- allows running scripts in Jenkins context (with 
> Jenkins.instance available). 
>
> Java/Groovy API reference:
> http://javadoc.jenkins.io/
>
> // getting any job:
> def job = Jenkins.instance.getItem("some-job-name");
> // BUT`job` here is not just a Job 
> , it is an 
> AbstractProject 
> .
>
> // set desc. for current build
> build.setDescription(someDescriptionString);
>
>
So I'm a little confused as to setting job to a value, but then referencing 
build.setDescription afterwards... or should that be job.setDescription?
  

> // loop over jobs (possible also in Script Console)
> for (item in hudson.model.Hudson.instance.items) {
>   println("Saving " + item);
>   item.save();
> }
>
> Do I need to save them all, or just the one I modified? Like job.save(); ?

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/466e86b9-520f-4ed6-ac61-ca23d4bba888%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A job to update other jobs

2017-05-12 Thread Morgan Blackthorne
Hey man, long time :) Hope things are good.

I'll keep this in the back pocket but I think the groovy setup is probably 
more along the lines of what I should use, thanks.

On Tuesday, May 9, 2017 at 10:38:28 AM UTC-7, Kevin Burnett wrote:
>
> what is up morgan, man? :)
>
> i just tested this to update a job description (it gets an http 302 when 
> it works):
>
>   curl -u user:pass -X POST 
> https://ci.example.com/job/my-hot-job/submitDescription --data-urlencode 
> "description=FROZEN by [fancy_business_here]"
>
> maybe someone else knows all about updating jobs from xml files.
>
> good luck,
> kb
>
> On Monday, May 8, 2017 at 2:06:33 PM UTC-4, Morgan Blackthorne wrote:
>>
>> We're using Chef automation around configuring our Jenkins jobs. 
>> Basically chef clones a git repo with the job XML files, and then tells 
>> Jenkins to use them.
>>
>> What we want to have is:
>>
>>1. One job to edit other jobs description to say "FROZEN by  
>>at " or to remove the FROZEN line (basically a toggle)
>>2. Chef will then be updated to look at the job XML currently on the 
>>Jenkins server
>>   1. If the description includes FROZEN, skip that job and leave it 
>>   alone
>>   2. If the description does not include FROZEN, update the job from 
>>   the XML file
>>
>> I'm not really up to speed on Groovy, so what's the simplest way to 
>> approach this? (I already know how to do the XML check for step 2, we can 
>> just look at the XML over HTTP.)
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/6f50c894-b247-4915-be28-f24420d71cb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: A job to update other jobs

2017-05-10 Thread 'Maciej Jaros' via Jenkins Users

Morgan Blackthorne (2017-05-08 19:56):
We're using Chef automation around configuring our Jenkins jobs. 
Basically chef clones a git repo with the job XML files, and then 
tells Jenkins to use them.


What we want to have is:

 1. One job to edit other jobs description to say "FROZEN by 
at " or to remove the FROZEN line (basically a toggle)
 2. Chef will then be updated to look at the job XML currently on the
Jenkins server
 1. If the description includes FROZEN, skip that job and leave it
alone
 2. If the description does not include FROZEN, update the job
from the XML file

I'm not really up to speed on Groovy, so what's the simplest way to 
approach this? (I already know how to do the XML check for step 2, we 
can just look at the XML over HTTP.)


This should get you started...

Install Groovy plugin 
. Use Groovy 
system step -- allows running scripts in Jenkins context (with 
Jenkins.instance available).


Java/Groovy API reference:
http://javadoc.jenkins.io/

// getting any job:
def job = Jenkins.instance.getItem("some-job-name");
// BUT`job` here is not just a Job 
, it is an 
AbstractProject 
.


// set desc. for current build
build.setDescription(someDescriptionString);

// loop over jobs (possible also in Script Console)
for (item in hudson.model.Hudson.instance.items) {
  println("Saving " + item);
  item.save();
}

--
You received this message because you are subscribed to the Google Groups "Jenkins 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/08353e5a-6d3e-f01a-1b44-99dd15a3ae4c%40mol.com.pl.
For more options, visit https://groups.google.com/d/optout.


Re: A job to update other jobs

2017-05-09 Thread Kevin Burnett
what is up morgan, man? :)

i just tested this to update a job description (it gets an http 302 when it 
works):

  curl -u user:pass -X POST 
https://ci.example.com/job/my-hot-job/submitDescription --data-urlencode 
"description=FROZEN by [fancy_business_here]"

maybe someone else knows all about updating jobs from xml files.

good luck,
kb

On Monday, May 8, 2017 at 2:06:33 PM UTC-4, Morgan Blackthorne wrote:
>
> We're using Chef automation around configuring our Jenkins jobs. Basically 
> chef clones a git repo with the job XML files, and then tells Jenkins to 
> use them.
>
> What we want to have is:
>
>1. One job to edit other jobs description to say "FROZEN by  
>at " or to remove the FROZEN line (basically a toggle)
>2. Chef will then be updated to look at the job XML currently on the 
>Jenkins server
>   1. If the description includes FROZEN, skip that job and leave it 
>   alone
>   2. If the description does not include FROZEN, update the job from 
>   the XML file
>
> I'm not really up to speed on Groovy, so what's the simplest way to 
> approach this? (I already know how to do the XML check for step 2, we can 
> just look at the XML over HTTP.)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/fa729891-a5fe-44c8-9f6c-cafb050a5985%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


A job to update other jobs

2017-05-08 Thread Morgan Blackthorne
We're using Chef automation around configuring our Jenkins jobs. Basically 
chef clones a git repo with the job XML files, and then tells Jenkins to 
use them.

What we want to have is:

   1. One job to edit other jobs description to say "FROZEN by  at 
   " or to remove the FROZEN line (basically a toggle)
   2. Chef will then be updated to look at the job XML currently on the 
   Jenkins server
  1. If the description includes FROZEN, skip that job and leave it 
  alone
  2. If the description does not include FROZEN, update the job from 
  the XML file
   
I'm not really up to speed on Groovy, so what's the simplest way to 
approach this? (I already know how to do the XML check for step 2, we can 
just look at the XML over HTTP.)

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/64f89b7c-e531-448b-bd74-89d1c62dc49f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.