I pass multiple files as parameters to my jenkins job. I have scheduled the job to run at regular intervals. I have installed the parameterized-scheduler plugin but I am unable to figure out the syntax for scheduling the job with the files as parameters.
If my file names are a.js, b.js, c.js. What would be the syntax for me to use the parameterized scheduler?
Is there another approach to solving this issue?
Syntax for parametrized scheduler:
*/2 * * * * %FILE=a.js
1-59/2 * * * * %FILE=b.js
* * * * * %FILE=c.js
Here, FILE is string parameter which accepts the name of file.
Note: Please change the interval accordingly.
I could not find an answer to this question although I have found a better approach.
The right way to solve this problem is to upload the files on a cloud repository that can be downloaded/cloned to the workspace during a build and then use the files.
So, I have uploaded the files to a github repo which I am cloning during a build and using them.
Related
I currently configure this setting with the job DSL like this:
it / 'triggers' << 'com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger'{
spec 'H H/4 * * *'
interval "43200000" // 12 hours
}
I don't understand the spec argument. I first made the config in the UI and just looked at the job xml and used those parameters.
This is what the config looks like if I set it to 30 mins in the UI:
<com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger plugin="cloudbees-folder#6.729.v2b_9d1a_74d673">
<spec>H/5 * * * *</spec>
<interval>1800000</interval>
</com.cloudbees.hudson.plugins.folder.computed.PeriodicFolderTrigger>
The interval setting is obvious, but what is spec? The UI gives me one argument but the job DSL has two. I can't find documentation on this.
What is "spec" here? Is it the time of day the interval begins? Why doesn't the UI surface this argument?
Is it possible to get Jenkins build duration using scripts or using some inbuilt functionality. I tried with ${BUILD_DURATION} but it didn't work.
Can anyone please suggest?
Here are a couple of options:
RESTFUL API
Use a language of your choice to consume Jenkins Restful API to get the json for the build and deserialise.
DECLARATIVE PIPELINE
Use ${currentBuild.durationString}.
The currentBuild object exposes a number of relevant attributes:
timeInMillis:
time since the epoch when the build was scheduled
startTimeInMillis
time since the epoch when the build started running
duration
duration of the build in milliseconds
durationString
a human-readable representation of the build duration
Navigate to https://<your-jenkins-instance>/pipeline-syntax/globals#currentBuild for the complete list.
I am Jenkins beginner & below Groovy script is an easy approach;
def item = Jenkins.instance.getItem("<Job_name>")
def last_job_duration = item.getLastBuild().getDurationString()
println last_job_duration
After system restart where Jenkins is stored, one of the jobs is constantly failing it is trying to create bulid with number 1 but there is already 1400 past builds. Is there a way to change it so the build will be created with correct increment so in this case 1401.
Full stactrace from jenkins:
java.lang.IllegalStateException: [Directory]\builds\1 already existed; will
not overwite with [Build.Name] #1
at hudson.model.RunMap.put(RunMap.java:189)
at jenkins.model.lazy.LazyBuildMixIn.newBuild(LazyBuildMixIn.java:178)
at hudson.model.AbstractProject.newBuild(AbstractProject.java:1011)
at hudson.model.AbstractProject.createExecutable(AbstractProject.java:1210)
at hudson.model.AbstractProject.createExecutable(AbstractProject.java:144)
at hudson.model.Executor$1.call(Executor.java:328)
at hudson.model.Executor$1.call(Executor.java:310)
at hudson.model.Queue._withLock(Queue.java:1251)
at hudson.model.Queue.withLock(Queue.java:1189)
at hudson.model.Executor.run(Executor.java:310)
You can use a groovy script in $JENKINS_URL/script as follows:
item = Jenkins.instance.getItemByFullName("jobName")
item.updateNextBuildNumber(1401)
It looks like you can use the "Next Build Number" plugin to accomplish this: https://wiki.jenkins.io/display/JENKINS/Next+Build+Number+Plugin
There is a file you can edit: $JENKINS_HOME/jobs/../nextBuildNumber
$ cat /var/lib/jenkins/jobs/my-project/branches/develop/nextBuildNumber
42
You will need to reload configuration after changing it.
I'm using Jenkins 2.46.2 version. I have installed Parameterized Scheduler plugin to trigger the build periodically with different parameter.
But it fails to trigger the build at scheduled time.
You have a problem with the ";" on parameters.
you have to insert space after each parameter, for example:
H/2 * * * * % EndMarket=can ;GitBranch=DevelopmantBranch
try without spaces between params, like:
0 8 * * * % base_url=https://www.example.com;suite_type=Regression
I installed the plugin on Jenkins 2.67, and it works. I had the same problem with builds failing to trigger with earlier version of Jenkins.
in my case, my parameter is Choice Parameter, so if I set the scheduler below and 'valueabc' is not in the list of choice, it will fail to start
H/15 * * * * %name=valueabc
I am trying to do a simple housekeeping pipeline to delete old workspace dirs within Jenkins.
node {
stage 'Housekeeping stage'
echo "Deleting all old cell directories, older then ${env.MAXIMUM_CELL_LIVE} days"
new File("${env.phaser_dir}\\workspace\\").eachDir() { dir ->
long diff = new Date().getTime() - dir.lastModified()
if (diff > env.MAXIMUM_CELL_LIVE.toInteger() * 24 * 60 * 60 * 1000) {
dir.deleteDir()
}
}
}
The result is that it iterates only once each time, deleting just one directory.
I have latest version of Pipeline at 2.2. I've also googled there used to be problems like this with .each iterator, but that supposed to be fixed?
Many Thanks
Michal
This is a known issue with Jenkins pipelines (former workflows) and it's filed in JIRA as JENKINS-26481.
Note that there's a lot happening behind the scenes in the Jenkins workflow; after every line Jenkins saves the state of the workflow (position in loops, local variables etc.) to be able to survive failure and resume processing. That's why fixing this problem within Jenkins is not trivial.
There's an easy workaround for you though - just move the logic into a separate function with #NonCPS annotation.
More information is available in the plugin documentation.