Schedule Jenkin builds with custom parameter using a config file from SVN? - jenkins

As the title suggests, is there anyway for me to schedule jenkins builds with custom parameters, using a JSON or HTML, or any kind of file that I can just push to my SVN/Git and Jenkin will pull/check periodically and build as scheduled?
I want to format the builds with something like this:
{
time:[
year: 2022
month: 7
date: 20
hour: 06
min: 00
]
BuildNumber: 1
BuildParams: {
UPDATE: 1
VERSION: 1000a
BUILD_TYPE: Beta
}
}
The time can be in x days instead of exact date. And the build params (UPDATE, VERSION, BUILD_TYPE...) are exact build params of the current pipeline script.
It would be best if the config file can be pulled from git or SVN but even it's a local jenkins setting it's still a huge improvement compared to before.
Thanks in advance.

Related

Is there a way to get notified when the build output changes in Jenkins?

I'm doing some batch work using Jenkins.
And I want to be notified when the output of the stand output is different from the previous build.
For example,
If I run the following bash shell on jenkins, the output of the previous build will be different if the build date is changed.
# /bin/bash
date "+DATE: %Y-%m-%d"
build - #1
DATE: 2018-06-05
build - #2
DATE: 2018-06-05
build - #3
DATE: 2018-06-06
Can I get notifications like email, slack, etc. only when the execution result is different from the previous one, as in the above build 3?
Could you let me know if you have a plug-in that makes this possible or if Jenkins already supports it?
I am very grateful for your help.
:)
Don't know if there is a plugin but in pipeline it's possible. Get current build log with: currentBuild.rawBuild.getLog(number_of_lines) and then compare it with the previous build log: Jenkins.getInstance().getItemByFullName('build_name').getBuildByNumber(env.BUILD_NUMBER.toInteger() - 1).logFile.text
If they are not equal send email: emailext body: 'build produced a different output than previous', subject: 'notification', to: 'me#mail.com'

Jenkins is showing "zombie" pipeline runs after restart - how to purge?

After restarting our Jenkins 2.107.2 instance, it shows many previously finished pipeline runs in the "master" section of the homepage, with a partly-completed progress bar.
When looking at the console log for these runs, they were completed days ago (long before the restart), but are showing a "resuming" message afterwards.
[Pipeline] End of Pipeline
Finished: SUCCESS
Resuming build at Tue May 01 06:02:42 PDT 2018 after Jenkins restart
Resuming build at Thu May 03 16:11:45 PDT 2018 after Jenkins restart
How can I purge these old runs from Jenkins (where does Jenkins keep the state for these runs)? I have hundreds of them; stop/kill doesn't remove them either.
I see this in the run's build.xml file - is that what's causing it?
<completed>false</completed>
https://issues.jenkins-ci.org/browse/JENKINS-50199 seemed to be the root cause.
After updating the pipeline plugins (latest "stable" versions as of 2018-05-07), the zombie runs disappeared and all is good again.

Any condition in Jenkins for Build Periodically do build only when changes found

I am using build periodically option schedule H 23 * * *
Would last have run at Friday, January 19, 2018 11:17:51 PM EST; would next run at Saturday, January 20, 2018 11:17:51 PM EST.
This is triggered everyday even when changes are not found. How can I make build periodically be triggered only when modifications are found?
Here in my case not using any version controls only nexus repository
Please let me know the solution that would be great....
Thanks....
You can set Jenkins to Poll SCM which means it will check whatever Source Control Management you are using (eg. Git or SVN) for changes and perform a build only if changes are found.
This blog post has some great screenshots and more information on how to set this up.

Jenkins: build job regardless revision

I use GitHub as CSV. I want my Jenkins job to be built each time I trigger it regardless revision.
Unfortunately, if there are no any new pushes my job refuses to build:
[poll] Latest remote head revision on
refs/heads/My_Brench is:
f405ced00e0e64ece71658a1b179ef4ed0db2deb - already built by 13.
Job status: [My Job] subjob has no changes since last build. Using strategy:
Default
How can I avoid this skipping already built by 13 and build it anyway?
It seems that you're using https://wiki.jenkins-ci.org/display/JENKINS/Multijob+Plugin
With that plugin you can define boolean parameter hudson.scm.multijob.build.always in your parent job and if the value of this parameter is true all your sub-projects will be built regardless of SCM changes.

Make jenkins auto build one a day but build only when there are source code changed

I have problem in configure jenkins to auto build and deploy java project. I want to build and deploy once a day. However this build only there are changes during the day. IF there is no changes, I don't want jenkins to auto build and deploy.
Note: that I used gitlab as source code management.
Can you help me with this configuration.?
Firstly, you should configure the Git SCM section at the top of the job config page to point to your GitLab repository.
Then you can use the built-in "Poll SCM" build trigger — this will periodically check whether your source code repository has changed — and if it has, a build of this job will be started.
If the repository has not changed since the last build, then no build will be started.
You can configure this trigger — whether using a cron-like syntax, or a shortcut like #daily or #midnight — so that Jenkins only checks the source repository once a day.
Additionally, you should make sure that the "ignore post-commit hooks" option is enabled. If you're using webhooks from your Git repository to start Jenkins jobs whenever a commit occurs, this option prevents your once-per-day job from being triggered for every Git commit.
Here's the detail document: "Jenkins CI integration"
http://doc.gitlab.com/ee/integration/jenkins.html
Update to match your comment.
You don't want to trigger the Jenkins build via webhook. It's ok.
You want to check the code change 1 time a day.
Example on Linux, build at 6:00 AM if there's any code change.
Install
https://wiki.jenkins-ci.org/display/JENKINS/PostBuildScript+Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Text-finder+Plugin
Build Triggers
Build periodically: 0 6 * * *
Execute shell
Like this
SINCE=`curl http://192.168.0.1:8080/job/MyJava/lastStableBuild/buildTimestamp?format=dd-MMM-yyyy`
cd /opt/code/myjava/
git log --pretty="%h - %s" --author=gitster --since=$SINCE --before=$SINCE --no-merges -- t/
Post Build actions
Post build task
Log text: commit
Operation: AND
Script: Your script to build your Java
Jenkins text finder
Also search the console output
Regular expression: Could not match
Unstable if found

Resources