Hudson / Jenkins: share parameters between several jobs

若如初见. 提交于 2019-12-07 02:55:07

问题


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...


回答1:


Go to your Jenkins home and navigate :

  1. Manage Jenkins >
  2. Configure System >
  3. Global properties >
  4. Environment variables > ....



回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/12427871/hudson-jenkins-share-parameters-between-several-jobs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!