i'm trying to figure out how can i add an administrative build to Jenkins that will manage a few builds, and how can i path the parameters from the administrative build to the child builds.
-
Did you try the suggestion? – Technext Aug 16 '14 at 06:21
1 Answers
Parameterized Trigger Plugin is what you're looking for.
Once you've installed the plugin, refer 2nd snapshot below. Go to Configure
page of your project. Search for Build > Add build step > From drop-down menu, select Trigger/call builds on other projects
. After that, click on Add Parameters > From drop-down menu, select Current build parameters
Above snapshot is of parent job A where i am defining a string parameter, which will be utilized in its child job B.
Above snapshot is again of parent job A where i am specifying the downstream (child) job B and also enabling Current build parameters
, which will ensure that the parameters defined in parent job A are visible to child jobs. Once we are done with these settings, we should be able to see the upstream job link in the child job B as shown below. This will confirm that things are fine till now. :)
Now the only task left is using/calling the variable (defined in parent job A) in child job B. This is shown in the below snapshot:
I tested it on Windows so i used
%string%
.If you're on UNIX/Linux machine, select 'Execute shell' and use
${string}

- 7,887
- 9
- 48
- 76
-
so all this steps i have to perform on my downstream build not on the upstream right? – Alex Brodov Aug 14 '14 at 15:42
-
-
Let me know whether you're aware about how to add parameter in a job. – Technext Aug 14 '14 at 15:52
-
the thing is that the upstream job is set as Build Flow and it doesn't have this option. i have this option only in the downstreams.. I have this option in my upstream "post-build Action" -> Trigger parameterized build on other projects -> then i've entered in the "projects to build" my childstream" and chose current build parameters. Is it the right way to do that? After i've done this how can i access this parameter from the child stream that specified let's say the name of this parameter "VERSION_NUMBER" ? – Alex Brodov Aug 14 '14 at 15:59
-
Ok. I guess you do not have 'Parameterized Trigger Plugin' installed. Are you fine with installing the above plugin or do you want to try with the one you already have? – Technext Aug 14 '14 at 16:05
-
I just tried installing Build Flow plugin but i could not find 'Trigger parameterized build on other projects' in 'Add post-build action'. I suspect you already have installed 'Parameterized Trigger Plugin'. Just for testing purpose, i suggest you create a fresh project and make sure to select 'Build a free-style software project'. We can then move further to troubleshoot your issue. – Technext Aug 14 '14 at 16:16
-
actually it's installed "parameterized-trigger plugin is already installed." but the thing is that what you are telling me is true about the childstreams because the upstream is configured as a Build Flow, let's say that i've configured everythig as you said how can i access this parameter from the childstream or from one of the bash scripts that i'm running on the childstream? Is it going to like this $VERSION_NUMBER – Alex Brodov Aug 14 '14 at 16:19
-
If you have set up the "Trigger parameterized build on other projects" section as i described above and more importantly, `enabled` the 'Current build parameters' as shown in the snapshot above, then in the child build, $VERSION_NUMBER will print the version as long as you have defined the same variable (VERSION_NUMBER) in upstream job and assigned it a value (say some default value). – Technext Aug 14 '14 at 16:29
-
The thing is if i'm selecting 'Build a free-style software project' i don't have the Flow option which has inside the 'Define build flow using flow DSL' where i can type the flow of the childbuilds.. Maybe you are familiar with another way to configure this flow.. – Alex Brodov Aug 14 '14 at 16:32
-
-
build("b") build("c") by the way i've passed this parameter (VERSION_NUMBER) form the upstream to the child stream but the child sctream hasn't recognized the value of this parameter – Alex Brodov Aug 14 '14 at 16:40
-
Your build-flow is straight-forward and can be easily implemented. Also, i tried a sample build after defining a variable and printing it in child job and it worked fine. Did you try your test on Build-Flow job? – Technext Aug 14 '14 at 16:47
-
yes i've created a Build-Flow job then i set up a parameterized String in this build, i called it VERSION_NUMBER and in the post-build Actions i added 'Triger parameterized build on other projects' and chose current build parameters -> then tried to access this parameter from one of my scripts that are running on downstream and it printed {env.VERSION_NUMBER} and not the value that i've entered. Maybe i need to configure anything else in the downstream? – Alex Brodov Aug 14 '14 at 17:05
-
I suggest you leave the Build-Flow plugin and use the 'Parameterized Trigger Plugin'. I use this plugin extensively in many of my builds and your DSL is very easy to configure. I have added few snapshots and i feel that might help you. Please create all jobs using 'Build a free-style software project'. Just follow the snapshots and you will be able to use the variable in your downstream job easily. :) – Technext Aug 14 '14 at 17:22
-
So, i've checked it, and defined a string parameter in job A and added a build step as you suggested, in the projects to build i wrote project B, but i can't see on the main page of project B the link to project A which should be the upstream, by the way i didn't understand where have you defined the link between this projects.. How jenkins should recognize that A is upstream? – Alex Brodov Aug 17 '14 at 08:13
-
Seems you have not read my _detailed_ answer above. :) I had clearly written after the second snapshot that _Above snapshot is again of parent job A where i am specifying the downstream (child) job B_. So unless you define the job name B in configuration page of job A, you will not be able to see the link to project A in project B. – Technext Aug 17 '14 at 08:43
-
So the thing is that i didn't understand where exactly i need to specify the downstream (child) job B. I haven't found any field in job A that says set a downstream.. – Alex Brodov Aug 17 '14 at 08:48
-
Have you installed `Parameterized Trigger Plugin`? If that is installed, _only_ then will you find the option in the dropdown of `Build` section (shown in snapshot #2) – Technext Aug 17 '14 at 09:18
-
Yes, it's installed.. i'VE Added the Trigger/call Builds on other projects, i can see on Job A main screen: Subprojects Static B(non-blocking) but i can't see on my upstream which is A the childstream B as in the snapshot that you've attached.. By the way what i want to do finnaly with this is to build just job B without A so A will manage B and C – Alex Brodov Aug 17 '14 at 09:49
-
Thanks a lot it's working now! Now I need to set more complicated job that will manage about 5 jobs with some conditions, is it possible to set it without DSL? – Alex Brodov Aug 17 '14 at 10:12
-
Yes, it is possible but i think it's beyond the scope of the original question that you raised. I would suggest you raise a new post for that along with all the details you need. – Technext Aug 17 '14 at 11:19
-
How can i add the properties of job B to job C from the Properties Content: For example i've defined there some variable 'directory' that holds the directory name - and i want to path it to job C. I've added a post-build triger - > Trigger parameterized build on other projects - > entered Job C and chose current build parameters, but it's not passing the properties that i've defined in job B – Alex Brodov Aug 17 '14 at 11:32
-
Where exactly is `Properties Content`? In which section did you use it? I could not find it. I defined a _String Parameter_ in job B and used the same string parameter in job C and it worked. – Technext Aug 17 '14 at 11:51
-
Under Build Environment you have a checkbox "Inject environment variables to the build process" -> "Properties Content" where you can define all the extended environment vatiables: for example home_directory where you'll store the path, and you can access it via the bash scripts or through any other method. So my question is how can i path this properties from job B to job C . – Alex Brodov Aug 17 '14 at 13:05
-
I don't have the [EnvInject plugin](https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin) installed but you can pass the dir name by simply using _Parameters from properties file_ option. This option is in the same dropdown where you selected _Current build parameters_. Create a file and put the variable and its value in the file, for ex., `dir=ABC`. Now specify the file location in the box _Use properties from file_. That's it. I have tested it and it works. I am able to see the value of dir in my child job C. – Technext Aug 17 '14 at 13:57
-
Is it a txt file or it should have some special extension like .properties? – Alex Brodov Aug 17 '14 at 14:27
-
It can be anything, even without an extension. Just make sure that you are specifying the full path. – Technext Aug 17 '14 at 14:29
-
It didn't work. This is what i wrote in the file: someVar=test1212 ravenDir=/net/TLV-RAVEN-BLD3/ccstore/builder/hudson/workspace/RavenApp1.5.5.0_Plat_Mig/builder_RavenApp1.5.5.0_Plat_Mig/vobs/ravenp/Raven/ This is how i tried to print it from the script: echo testing ${someVar} It didn't print the value of the var – Alex Brodov Aug 17 '14 at 15:15
-
It has to work unless you skipped some part of what i mentioned. Did you get the option _Parameters from properties file_ in the same dropdown where you selected _Current build parameters_ earlier? If yes, then did you specify the _correct absolute path_ to the properties file? If yes, then try baby steps: just put `dir=ABC` in the file and print the variable (`echo $dir`) in the **same job** and see whether you get ABC as output. – Technext Aug 17 '14 at 16:15
-
-
Thanks it's working, I'm wondering if there is a way to path a content of a txt file as a parameter so my script will be able to use the string inside – Alex Brodov Aug 18 '14 at 18:24
-
I guess your new concern has already been answered [here](http://stackoverflow.com/questions/25350570/jenkins-how-can-i-upload-a-text-file-and-use-it-as-a-parameter), correct? :) – Technext Aug 19 '14 at 12:26
-
@user3502786: Request you to close this link if you feel it has been answered: `http://stackoverflow.com/questions/25311133/jenkins-how-can-i-pass-parameters-from-the-upstream-to-downstream`. If it doesn't, then please let me know your concern. – Technext Aug 19 '14 at 15:10
-
I think that for now i found a solution, i'll build a small script that will cat the txt file into a variable and then i'll call my next script with this parameter. – Alex Brodov Aug 20 '14 at 09:16