Cannot receive parameter from Script content to Predefined Parameter in Jenkins - jenkins

I would like to pass hostname parameter which is declared at Script Content to Predefined Parameter in Trigger/calls on build other project where my child project will receive parameter from the parent project.My code looks like this in Script Content:
`machine_name="$(hostname)"`
So in order to pass my parameter to the child project I declared:
host_name=${machinename}
in Script Content .But when I check in my child project it display as ${machinename} which is not I want .Can someone tell me what am I missing or what step that I done wrong or is there any way to perform this ?

Try using ENv Inject plugin, all you need to do is below:
Your script should contain below step:
machine_name="$(hostname)" > inject.txt
Now use Inject environment variables build step and in
property file path give inject.txt
what's the use?
By this step, now you machine_name variable holds the hostname value throughout the job.
Next, in your Parameter in Trigger/calls on build other project
host_name=${machine_name}
And use the same variable in child job.
I think there is no need for multiple assignments above, but still you can try this.

'_' was missing. host_name=$machine_name.
you cannot set or pass the parameter value from the script o/p. either make it as env variable using groovy or set in to property file & read.

Related

How to change a tfs build variable in script

I'm using TFS2015 update 1. I want to pass information from one build step to the next, how is this possible?
That seems like a very simple task, but I can't figure out how that's suppose to work. Passing a variable to a build step is easy, but passing information from one step to the next seems to be impossible. I hope I'm wrong.
You can call the task.setvariable Logging Command, which sets a variable in the variable service of taskcontext. The first task can set a variable, and following tasks are able to use the variable. The variable is exposed to the following tasks as an environment variable.
Example:
##vso[task.setvariable variable=testvar;]testvalue

i want to make generic parameters in jenkins

How can I make generic parameters in jenkins that will be updated automatically for example I want to be able to create a parameter which hold today's date and it will be update automatically and not manually ?
thanks!
You might want to use EnvInject.
Setup your job and then add a build step "Inject envornment variables" from a file with an absolute path or the path relative to current job's workspace, which will contain something like:
DATE_VARIABLE="20150708"
OTHER_OPTIONAL_VARIABLE="value"
In previous execute shell step you may for example do:
echo "DATE_VARIABLE="`date +"%d%m%Y"` > env_inject.txt
After all that you don't need Parameters for a build, since you will have the needed parameter injected as an environment variable.

Inject environment variables plugin is passing value as "12345"

I am using "Inject environment variables" Jenkins plugin to pass values to child jobs. Property file name is config.Today_date(eg. config.0403) and it has two parameters in it 1. change list(eg. 175444) 2. today's date(eg. 04032014). In child job Properties file path is config.${Today_date}($Today_date is predefined parameter in parent job).
First issue is: it error out saying config."Today_date" do not exist. I went to location and found property file is there and realized that child job is searching properties file as config."Today_date"(config."0403")and actual name of file is config.today_date
Second issue is: if i put property file name as config.0403(today_date) in Properties file path, Then it successfully locate the file but where ever it use parameters from this file, it use them as "0403" & "175444"
Please advise how i can solve "" issue at both locations.
Thanks !!

Updating the Jenkins Variable with a value calculated in a batch file

I am new to Jenkins. My aim is to define a build job in which I have created an environment variable suppose "x" by checking "This build is parameterized" option. I am executing a batch file which is performing a set of instructions and I want the x to be updated by a value calculated in batch file. Any suggestions how can I update the Jenkins variable value calculated using a batch file. I have tried using enviject plugin but not getting how to update the variable.
Thanks in advance
enviject plugin should be helpful here.
But - you need to update your batchfile to create a property file.
As the first step in the build action, I am passing some properties to my test.
Then, I use the property name like a parameter passed to Jenkins to execute a windows batch command. This bat file creates a result file in .properties format.
As the third step, i read the (result) property file. The result property file can have the same properties with updated values.
Now - your original proeprties would have been updated with new values & can be used in your subsequent build steps.

How to set Environment Variable so that it can be used in Jenkins

I am using an Environment Variable so that that it can be modified and Recipient List will consume that environment variable.
So this value is passed as a build parameter:
Followed to that I am modifying it. Just as an example:
Now I am accessing this value in the recipient list:
Unfortunately Jenkins is not able to get this new value. It is using the old value. How this behavior can be fixed?
We need to use the EnvInject Plugin. One of the features is a build step that allows you to "inject" parameters into the build job from a settings file.
Create a property for the email list in the env.properties file:
echo "email_list=`dummy#test.com`"> env.properties
It will create the properties file in the job workspace directory.
env.properties
In Recipient list access this variable using the following:
"$email_list"

Resources