How to tell Jenkins about multiple SCM via Jenkinsfile - jenkins

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).

Related

Jenkins pipeline for multiple repo

I am working on micro-service base Jenkins pipeline. There is similar code pattern / structure in Bitbucket repository for Java and angular based code. Can I manage multiple repositories with single pipeline with dynamic approach which can provide filter option (like AJAX in java) in drop down like I can get more than one repositories in drop down option and I can select any repository, based on this repository, I can get branches from this repository in next drop down and I can execute Jenkins pipeline.
Do we have any Jenkins plugin which can provides filter option for Bitbucket repositories in Jenkins.
Presently I am using Git parameter option in Jenkins pipeline (Build with parameter) and then created several pipelines.
Are you saying that you want a job in which you can select a repository and then select a branch from that repository and hit GO and build that branch of that repo? If this is the case then the answer is no.
You would have one Job per repository, and if that job is a multibranch pipeline then you would be able to select the branch to build from there.
You can enable all the repos and branches to use the "same" pipeline that you then submit parameters to using a Shared Library

Polling from multiple repositories in Jenkins

I couldn't find an answer for my question on stack, sorry if it is a duplicate.
Let's say I have repo A on Github, where my Jenkinsfile is, and repo B on Github, where all my source code is.
For my job, I've set 'Pipeline script from SCM' from repo 'A', added 'Polling ignores commit in certain paths' with included region containing only this Jenkinsfile.
In Jenkinsfile, I'm using checkout plugin to pull repo 'B' with added PathRestriction extension.
Also I've added pollSCM to 'triggers' with value 'H/5 * * * *'.
But whenever I commit something to repo 'A' without any changes to this Jenkinsfile, build is triggered anyway.
My question is: How can I setup my build to trigger only, when Jenkinsfile in repo 'A' or my source code is changed?
There are two ways to trigger a build only when specific file changes.
 1. script hook: On git server side, create a hook that will check if the last commit changed the Jenkinsfile, if true, send a post to jenkins job configured with 'Trigger build remotely'.
 2. Commit: Create a repo only with the Jenkinsfile, so every commit on this repo will be a change on Jenkinsfile.
I strong advise you to change your approach and use Jenkins shared library, this is a much better way to share and manager pipeline across multiple projects / jobs

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.

When Multibranch pipeline when job is trigged, what is stored in Jenkins workspace?

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.

Jenkins Multiple SCM Branch Selection

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

Resources