Jenkins Build periodically with parameters doesn't work - jenkins

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

Related

How do I properly configure the "Scan Multibranch Pipeline Triggers" setting with the job dsl? What is "spec"?

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?

How to create a new line in a CRON in jenkins

I have a question about new line in cron trigger in jenkins
I create a dynamic string such as
'cron': 'TZ=Europe/Berlin\n* * 1-5\n0 5 * * *\n'
using groovy script I want to set jenkins trigger, but the problem is, \n is not working.
Did I something wrong?

Parameterized Scheduler with File parameters - Jenkins

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.

How to safe guard against broken jenkinsfiles causing pipelines to run indefinitely?

I have my repo getting polled every 5 mins.
But I found that if the jenkinsfile is totally broken the pipeline will fail with "This stage has no steps".
Then every 5 mins it will retry it and keep failing.
How do I safe guard against this? Can I set a threshold somewhere so if this happens it doesn't churn forever?
If you are using scm polling, it should only build if there are changes. Sounds like you may be building on a cron schedule. Here is the different syntax for each in a declarative pipeline.
pipeline {
triggers {
cron('H/4 * * * 1-5')
pollSCM('0 0 * * 0')
}
}
Or you could do is trigger the builds from a webhook instead of starting a new build every 5 minutes.
If you really just want to throttle the builds so you can't do more than n builds in x time, you can set this property:
properties([[$class: 'JobPropertyImpl', throttle: [count: 1, durationName: 'hour']])

Jenkins .eachDir() iterate only once

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.

Resources