Aggregate multiple upstream SCM changes in downstream job - jenkins

On my current project, I have several dozen "sub-projects", each with trunk and branches (legacy setup, can't change it)
There are multiple commits on a branch, let's say 5, and then a branch is reintegrated to trunk. When a branch is reintegrated to trunk, it triggers trunk build as a downstream job.
I need this downstream trunk build to show all upstream SCM changes since last reintegration
I've used Display Upstream Changes plugin, however that only displays the last upstream commit in corresponding trunk build.
I've also used All Changes plugin. It does allow me to see "aggregate" list of upstream commits (either by date, promotion or number), but I cannot post these to downstream job.
Note: using SVN for SCM
Alternatively
Alternatively, if there is a way to include "merged revisions" in the SCM changelist, that would solve my issue as well

Jenkins naturally shows changes on a job.
A downstream job is linked only in a workflow sense. Do Job B after Job A. Linking two jobs in this way does not extend to showing changes.
Option 1
MultiJob Plugin
Option 2
You could get the list of changes in job A using groovy like this and pass it to Job B as a parameter to do something with. (Like print out to an HTML file and publish to the dashboard of Job B with the HTMLPublisher plugin).

Related

How to track if Jenkins Job is not referring to master branch?

I am facing an issue where I notice in my organisation sometimes engineers make changes to the Jenkins file and they change the Jenkins job branch inside the Branch Specifier (blank for 'any') section. Now, the issue is engineers sometimes forget to merge their changes from their dedicated branch to the stable branches such as the master branch for example.
I want to track all those Jenkins Jobs and send it an alert on Slack if the Jenkins Jobs are running from non-master branches. It will help me and my team to trace out easily the jobs which are not running from the master branch.
Sending alerts via Slack is easy, I am more interested in tracing the non-master branches.
Basically you want to receive an alarm if Jenkins is building a branch other than 'master'?
Since editing Jenkinsfile does not make sense (as your developers can change the file to their taste), you need to think of something else. One of my thoughts was to make Jenkins run on Jenkinsfile2 which would send your alarm and then just build Jenkinsfile. But that is not fully thought through (I guess this is not a full match: How to invoke a jenkins pipeline A in another jenkins pipeline B)
Another, easier to implement option could be to have another Jenkins job monitoring the same repository. It runs a pipeline directly coded in Jenkins that just checks the branch name and sends the alarm if need be. The branch name should be available

I have a use case which causes issues with Jenkins free style project poll scm

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.

Why would a job in Jenkins multibranch pipeline gets disabled

We are using Jenkins(v2.235.1) and BitBucket cloud combination. We have BitBucket Team/Project type job which has created multi-branch pipelines. Some of the jobs corresponding to individual branches are getting disabled even these branches in the Git repo are active. Not sure why this is happening.
Can you please share some insight on this and how we can prevent this from happening.
Below are my versions
Jenkins v2.235.1
Bitbucket Branch Source plugin v2.9.7
Bitbucket plugin v1.1.27
Thank you
If there is no Jenkinsfile at the root of the repository or if the name is misspelled or is with different letters casing, like JenkinsFile, the job will be disabled.
From https://www.jenkins.io/doc/book/pipeline-as-code/
Presence of the Jenkinsfile in the root of a repository makes it eligible for Jenkins to automatically manage and execute jobs based on repository branches.
Make sure you have only one jenkinsfile in your root directory. it is not a good idea to have more than one file with the name jenkinsfile which causes jenkins to disable the job. this could be one the reason why your job is getting disabled.
In addition to previous answers.
Jobs (branches/PRs/tags) also can be marked as disabled if you first start using all available discovering options (Bitbucket Team/Project -> Configure -> Behaviors -> Within repository -> Discover ...) and after that removed one or some of them. In this situation, a Child project of Bitbucket Team/Project indexes all branches/PRs/tags first (keep them active), and after the configuration was changed, it reindexes and disables unneeded items.
Also, jobs can be marked as disabled when Bitbucket Team/Project is configured in a way when both branches and PRs are discovered, but for branches configured the "Exclude branches that are also filed as PRs" strategy. In such a case, the branch that becomes a PR (a branch from which PR has been created) will not be tracked by Jenkins.

Jenkins Multibranch Pipeline: Differentiate between build triggered by branch indexing vs webhook

I have a Jenkins multibranch pipeline for github and currently it triggers builds whenever a branch is indexed. I have certain actions in my pipeline that I only want triggered whenever there are changes to a branch (on a webhook push). So I was wondering if there's a Jenkins environment variable that will allow me to distinguish between the two different type of builds. Or if there's a git solution to check when the last change was made to the branch and differentiate it that way

Jenkins P4 plugin triggers, trigger by branch

I am using the "P4 Plugin" - https://wiki.jenkins-ci.org/display/JENKINS/P4+Plugin in Jenkins v2.32.1.
I would like to trigger specific jobs in Jenkins, depending on what path is changed in SCM.
For example if something changes in
//depot/branchA
Build job A. If something changes in
//depot/branchB
Build job B.
As far as I can tell the plugin is only set up to trigger every job in Jenkins that has "Perforce triggered build." (building both A and B jobs) Am I missing something? I am currently using SCM polling and trying to move to a more efficient system.
This understanding is based on reading the "Triggering" section of https://github.com/jenkinsci/p4-plugin/blob/master/SETUP.md
You may be defining too broad a workspace, and causing Jenkins to trigger on every submit. The client workspace associated with job A should only map //depot/branchA/..., and the workspace for job B should only map //depot/branchB/....
Jenkins polls for changes, and if it sees any, triggers any build that has a matching path. So if both jobs had a workspace that mapped //depot/... then submits to branchA or branchB would trigger both jobs.

Resources