Jenkins Multiple SCM Branch Selection - jenkins

I want a jenkins job with multiple GIT projects. I want to select a particular GIT project and based on that I should be able to select the branch(similar to GIT plugin) to build.
Any plugins or other solutions to solve this?

There is no direct plugin solution for this. Previously we can do it using Multiple SCMs Plugin. But as of now, only one solution is using pipeline scripting, because that plugin is deprecated.
So, now you can do that by Jenkins Pipeline Scripts. You can see This post for further pipeline multi git scripting.

I solved this by adding a shell command (as a build step) that does an "old fashioned" git clone:
git clone https://$bitbucketUsername:$bitbucketPassword#<yourBitbucketServer>.com/scm/projectname/reponame1.git
git clone https://$bitbucketUsername:$bitbucketPassword#<yourBitbucketServer>.com/scm/projectname/reponame2.git

Related

How to build Jenkins after each push in any branch?

Is there any way to make Jenkins builds after each commit in any branch ?
Because i found in my project's configuration that Jenkins run build only after detecting commits in specific branch or in the default ( eq to master in git ).
PS: i'm using mercurial and Jenkins file.
Should i change project type ( new item type in Jenkins ) or are there any modifications in configs.
There are two things that you should check for this (I haven't work with Mercurial)
Does Mercurial has the option to create webhooks?
There is a jenkins plugin for Mercurial? (I think there is)
You must configure on the mercurial site the webhook pointing to Jenkins and give the point to the job you want to run, and on which events does it will fire. On the Jenkins side you must configure on the job who it will behave.
For example, with GitLab, the plugin has an option configured on the "Build Trigger" section where you configure the events and the branches that fires the job. In GitLab, in the repository you create the webhook, that is only a URL pointing to the Jenkins job.
I got this solution and it worked for me.
with Mercurial, we can use the "tip" keyword.The tip revision is the most recent changeset in the repository. It is the most recently changed head.

How to exclude repository from changelog

I have a freestyle Jenkins job with multiple git repositories.
I want Jenkins to ignore one of the repositories when generating the changelog for the build (such as for sending out emails or updating relevant Jira issues).
Is it possible to exclude one of the repositories from the changelog?
I ended up working around this problem myself by removing the the repository from the SCM section of my Jenkins job and writing a script to clone and checkout the repository as a build step.

How to run Jenkins pipeline automatically when "git push" happens for specific folder in bitbucket

I have started using Jenkins recently and there is only scenario where I am stuck. I need to run "Jenkins pipeline" automatically when git push happens for specific folder in master branch. Only if something is added to specific folder, than pipeline should run.
I have already tried SCM with Sparse checkout path, and mentioned my folder, but that's not working.
I am using GUI free style project, I dont know groovy.
I had the same issue and I resolved it by configuring the Git poll.
I used poll SCM to trigger a build and I used the additional behavior of Jenkins Git plugin named "Polling ignores commits in certain paths" > "Included Regions" : my_specific_folder/.*
By the way, using Sparse checkout path allows jenkins to checkout only the folder you mentioned.

Jenkins is checking out the entire SVN repo twice

I have a Jenkins Pipeline setup, and a Jenkins file which has the below content:
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Hey'
}
}
}
}
A post commit hook triggers the Jenkins build successfully, and I can see it starting from the Jenkins UI. It states that it is checking out the repo to read from the Jenkins file and it stores the checkout in the workspace#script folder on the server.
Checking out svn https://<svn_server>/svn/Test/Core into C:\Program Files (x86)\Jenkins\jobs\CI_Build\workspace#script to read JenkinsPipeline/Jenkinsfile
Checking out a fresh workspace because C:\Program Files (x86)\Jenkins\jobs\CI_Build\workspace#script doesn't exist
Cleaning local Directory .
After this is complete, I make a change to a file in the repo and the build triggers via the post commit hook happily, but then it tries to checkout the entire code base again into a folder called workspace. I would have expected that the checkout happens once and then the "use SVN update as much as possible" option would kick in and only update the changed files? Or maybe I have the wrong logic?
SVN version - 1.9.7
Jenkins version - 2.84
Jenkins has to know what is in your pipeline script before it knows if it should checkout your code. It is possible that your pipeline says not to check out the code, and you set into a subdirectory and fire off the checkout yourself. Or maybe checkout multiple repos in different places. Until Jenkins sees your Jenkinsfile, it can't know what you want. So it has to checkout the repo once to see your pipeline, then again to do the work.
With git (and maybe some versions of other repo plugins) lightweight or sparse checkouts are supported, so then it only grabs the jenkinsfile instead of the entire repo. I don't think this is a supported option in SVN yet.
Lightweight checkouts are now supported by the SVN plugin, the SVN plugin was updated in version 2.12.0 to add this feature - see https://wiki.jenkins.io/display/JENKINS/Subversion+Plugin.

How to tell Jenkins about multiple SCM via Jenkinsfile

To build my project, I need to pull 3 git repositories.
In the stage view, I only see the commits from 1 of those 3 git repositories.
How can I tell Jenkins about the other 2 repos?
I think that if you're using a Pipeline job then the suggestion from #Mor Lajb is working properly. You can basically specify the three git sources directly from the pipeline Groovy script.
Conversely, if you're using a multi-branch pipeline job then you probably need to select 'configure' from within your project and under 'branch sources' add as many git sources you need (use add source button).

Resources