I'm using Jenkins on a CI environment, with the plugin for SVN.
The build polls SCM every minute for new changes, and triggers if there are any.
The problem is that we need to change from one branch to another with regularity.
When this happens, the correct branch is checked out, but jenkins continues polling the old branch.
What do I have to do for it to always poll the correct branch?
EDIT:
With multibranch pipelines, it will create a sub-job for each branch. We can do the polling by just adding
triggers {
pollSCM('* * * * *')
}
under 'pipeline' on the jenkinsfile. Now these sub-jobs will not need to change branch, because there is one for each branch. This avoids the issue I was having before.
If you are using Jenkins 2, it is recommended to use the multibranch pipeline, along with jenkinsfile in the SVN repository
Related
I have a free style project which will trigger on commits. I have kept poll scm which polls for commits in remote repository. This jenkins job actually make some changes to a file after checkout and then commits+push back to remote repository.
This push by jenkins job is actually triggering back a new build due to scm poll for new commits is set in job. I want this job not to trigger again for self commit by job itself
It is not clear if you are using Git. In case you are and expect that the file will be always be changed by Jenkins, Git plugin in freestyle has options to ignore certain file paths.
If this specific file is expected to edited by user other than Jenkins than only solution I can think of is through conditional logic in jenkins pipeline-as-code.
I have a multibranch pipeline.
I want to detect new branches frequently, but I don't want to trigger build upon detection or anytime there is a change in the branch, instead, I want to do nightly build with detected branches.
I configured the pipeline to suppress automatic SCM triggers
and added this to the Jenkinsfile
properties([
pipelineTriggers([pollSCM('H 23 * * *')])
])
The problem is that the pollSCM config is applied only after the first build of the branch.
So if the multibranch job has detected a new branch, I would have to go and manually start a build for that branch, and only then the pollSCM will take effect.
Is there a way to automatically apply the pollSCM config upon detecting a branch?
I am not sure if I am asking the question in right way.
When I am triggering the multi branch pipeline job and I do "checkout scm" in Jenkinsfile, does it checkout the pull request or Master + pull request?
It depends of your settings.
As I remember, multibranch pipeline builds pull requests in separated view and it can build as PR source branch and result of PR. It cloned your repo, checkouts target branch, merges source branch into it and runs your stages.
If you look at the logs you will see that it checks out the hash of the commit
example: git checkout 1fb651dfdcbea276627de0247bbf5047840cae4c
As for workspace, if you log in to the Jenkins machine where this is running you will see that each branch has a separated workspace. Here you will find the source code of the checked out branch. The separated workspace ensures that there is no conflict when working with multiple concurrent branch builds.
I am migrating my old Jenkins free-style job to multi-branch pipeline. I also want to use GitLab hook with them.
My problem is the branch detection. I am doing it manually but I want it to be automatic: when a new branch is pushed to git, GitLab trigger a Jenkins job that trigger the branch detection if the branch parameter from GitLab is not known for Jenkins at the moment. Is this possible to do it or doesn't this exist?
FYI: I tried to launch the multi-branch pipeline job but Jenkins says:
ERROR: No parameterized job named XXX found.
Enable "Build Periodcally" in your multibranch job configuration and the branch indexing will automatically started.
What you really need is a branch source plugin for GitLab with webhook integration, which is tracked as an RFE in JIRA.
Failing that, use a plain Git branch source and configure GitLab to send Jenkins notifications to /git/notifyCommit (IIRC) as documented on the Git plugin wiki. Need specify only a url, no other details. The branch indexing this triggers should both detect new or removed branches, and changes to the head of an existing branch, and schedule builds accordingly.
You can set webhook in GitLab for push events and URL like http://<yourserver>/git/notifyCommit?url=<URL of the Git repository>.
See https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin#GitPlugin-Pushnotificationfromrepository
GitLab notifies Jenkins on push events which should trigger branch detection also for multibranch pipeline.
I didn't receive the answer I wanted and I ran into this issue today that answered the question :
https://github.com/jenkinsci/gitlab-plugin/issues/298
TLDR: Multi-branch pipeline are not supported yet to be triggered by gitlab commit easily. There is a workaround. Look at the link above.
Jenkins scm polling doesn't detect changes if we use parameter(environment variable) in branch field. Note that the environment variable is coming from the pipeline config and the job which does scm polling is part of the pipeline.
I'm using git plugin git-2.5.0-beta5
I spent 1.5 weeks on the same issue. There two ways for (in fact, only one) to build multibranch projects:
deprecated plugin
Multibranch pipeline job type
I hope this answer will save a couple of hours to next researchers.
Its a issue with Jenkins. The parameters are not set during polling.
try this WA.
https://issues.jenkins-ci.org/browse/JENKINS-33719?focusedCommentId=251585&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-251585