问题
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 thebuild.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 :
- Manage Jenkins >
- Configure System >
- Global properties >
- 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 linesname=value
(in my casessh.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