Jenkins issue with Trigger one build per property file - jenkins

Job A uses "For every property file, invoke one build" parameter factory to call downstream job B.
Here is the file pattern I am using:
d:\temp*.properties
There are two files in that folder:
build0.properties
build1.properties
each file looks something like this:
modified=SampleApp
Job B fails because job A is not setting the parameters from above file. If I look at the parameters for a build of Job B, they are empty.
The process works when I use "Parameters from properties file" parameter type instead of a parameter factory, and specify the full path to one of the files, so I know the files are in the right format. I do not want to add a parameter for each file I have,
since I will have these files generated dynamically.I would prefer to use the parameter factory if possible.

Issue with the file permissions, when I pointed to workspace directory with the file pattern It started workign fine.

Related

publish junit test result report from parent's workspace

I have a parent job and two child jobs in jenkins. The workspace shared by the child jobs resides within the parent job.
Now the child jobs are producing a Junit RspecFormatted logs (job1.xml and job2.xml), which is getting stored in the parent's job workspace.
I am trying to refer giving the full path:
$JENKINS_HOME/workspace/{parent-job}/{folder a}/{folder b}/{folder c}/test-results/job1.xml in the post build result section but the build fails to find this path.
Note: I am able to print the file in the Execute Shell section with this path
I'm not really sure about the issue, can you give me more details?
By the way if i understood your needs, you can use the:
https://wiki.jenkins.io/display/JENKINS/Parameterized+Trigger+Plugin
To get variables like TRIGGERED_JOB_NAME and NUMBER, so you can build the PATH
$JENKINS_HOME/workspace/${TRIGGERED_JOB_NAME}/{folder a}/{folder b}/{folder c}/test-results/job1.xml
What about folder a/b/c, where are these variable valued?
You can also simply pass these information as parameters and than use them as variables to dynamically build the path...
Let me know if it's clear and if it helped...

Jenkins parameterized build not creating file

Maybe I am misunderstanding the intended use for the Jenkins file parameter here...
I want to be able to upload a file containing some data (in my case comma separated variables). I then want to simply read this file and do stuff with the data. I've got this setup using a Pipeline job.
My file location is set to 'email_list.csv'. In my pipeline script I have
node {
stage('post') {
emailFile = readFile 'email_list.csv'
println "${emailFile}"
//.........
}
}
This fails with a java.io.FileNotFoundException: /var/lib/jenkins/workspace/job-name/email_list.csv (No such file or directory) exception
Shouldn't the parameterized build have set up this file? If not, how do I read the data uploaded?
Jenkins by default provides build job parameters as a params map in pipeline. It is a key-value pair. All you comma seperated values will be into values field. You can refer them in your groovy script as,
print params.emailFile
To dump it as a file, you can use writeFile library function.
P.S: If you print params in groovy script, you will be able to see all build parameters of your job.
There is a a bug since ages that makes impossible to use fileParameter:
Handle file parameters
file parameter not working in pipeline job

Cannot receive parameter from Script content to Predefined Parameter in 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.

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

SCP Jenkins Plugin does not copy selectively

I want to copy only specific files in a directory to remote server using Jenkins SCP Plugin.
I have folder structure /X/Y/...Under Y, I need only the files a b c among a b c d e f. Is this possible...?
Of course, to copy all files all you need is X/Y/**. But what about copying selectively.
I was reading somewhere that this is a kind of bug in the plugin.
I have string parameter, $FILES=x,y,z highlighted in "BUILD WITH PARAMETERS"
SCP Configuration:
Source: some/path/$FILES (relative to $WORKSPACE)
Destination: /var/lib/some/path
You should be able to say X/Y/a; X/Y/b; X/Y/c
Also remember that these files have to be under the job's ${WORKSPACE}
Alternatively, you can have another build step in-between that copies only the files that you want into a staging folder, and then supplying the staging folder to SCP plugin
Edit after OP clarification:
Your $FILES variable contains x,y,z When you supply this as Source to SCP plugin, it becomes:
some/path/x,y,z
Or if we break this one item per line:
some/path/x
y
z
The first item is valid, the next two are not complete paths, therefore are not found.
Several ways to fix it (chose either one):
Full path in parameter variable.
Under your FILES string parameter, list the full path, like:
some/path/x, some/path/y, some/path/z
Under SCP Source, use only $FILES
pros: quick and stable.
cons: looks ugly with long paths.
Wildcard path in parameter variables.
Under your FILES string parameter, list the global wildcard path (files will be found under any directory), like:
**/x, **/y, **/z
Under SCP Source, use only $FILES
pros: quick and looks better than long paths.
cons: only works if files x, y and z are unique in your whole workspace. If there is $WORKSPACE/x and $WORKSPACE/some/path/x, one will end up overwriting the other.
Prepare MYFILES variable and inject it.
You need an Execute Shell build step added. In there write the following:
mypath=some/path/
echo MYFILES=${mypath}${files//,/,$mypath} > myfiles.props
Then add Inject environment variables build step (get the plugin in the link). Under Properties File Path, specify myfiles.props.
Under SCP Source, use only $MYFILES (note you are reading modified and injected variable, not the original $FILES)
pros: looks good in UI, proper and further customizable.
cons: more build steps to maintain in configuration.
p.s.
In all these cases, a multi select Extended Choice Parameter will probably look better than a string parameter.

Resources