Hudson / Jenkins: share parameters between several

2019-04-29 12:52发布

I have about 20 jobs using common parameters (user, password), and sometimes the password expires... So I have to change it on all jobs, which is really time consuming (and error prone, I may forget one).

I thought about:

  • using a kind of magic property file if that exists to have directly lines like KEY, VALUE added into job parameters
  • adding the same kind of KEY, VALUE pair directly inside build.xml, but where ? And it's really ugly... Maybe with a dedicated XML embedded into the build.xml ?
  • calling a slave job that would (how ?) push up to the parent one the desired values...

As you can see I'm only starting in Hudson/Jenkins (I'm using Jenkins 1.424.2.2), thanks for your help !

EDIT: I'm not admin of the Jenkins instance, so I cannot have access to global properties...

3条回答
Root(大扎)
2楼-- · 2019-04-29 13:06

Go to your Jenkins home and navigate :

  1. Manage Jenkins >
  2. Configure System >
  3. Global properties >
  4. Environment variables > ....
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-04-29 13:11

I eventually succeeded by:

  • keeping encrypted credentials in a web page
  • retrieving them in Hudson thanks to a shell script (wget), decrypt them, and creating a build.properties file in the workspace with lines name=value (in my case ssh.password=...)

This works, because Ant build steps detect this file and pass the variables inside into their context. Thanks to that I could centralize my credentials.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-04-29 13:29

I can think of two approaches:

  • Use Global properties, found under Manage Jenkins -> Configure system. Here you can define environment variables that should be available to all jobs.

  • Write a small script that downloads, modifies and posts the job config: http://[jenkinshost]/job/[jobname]/config.xml.

You can read about the api capabilities under http://[jenkinshost]/job/[jobname]/api, here is what it says about reading and changing config.xml:

Fetch/Update config.xml

To programmatically obtain config.xml, hit [http://[jenkinshost]/job/[jobname]/config.xml]. You can also POST an updated config.xml to the same URL to programmatically update the configuration of a job.

查看更多
登录 后发表回答