-1

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.

torek
  • 448,244
  • 59
  • 642
  • 775

1 Answers1

0

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

Queeg
  • 7,748
  • 1
  • 16
  • 42
  • Hi Hiran, there are two parts. One is when you create a Jenkins job as a pipeline you clone the repository and pass the Jenkins file in the end under the `configure` section. And, each Jenkinsfile also sometimes clone another repository. I am interested in monitoring the first part, where my engineers change the branch name of Jenkinsfile inside the configure section. All I am currently a thing of is using some shell script or XML parser to parse config.xml for each job and look for a particular tag such as branch name to detect. But, not sure how other people handle this sort of scenarios – Mohit Sharma Nov 14 '21 at 09:17
  • I thought your engineers touch the VCS but not the Jenkins configuration. If you want to track that you might want to configure version control for jenkins. This tutorial may help: http://blog.vogella.com/2014/01/07/storing-the-job-information-of-jenkins-in-git/ – Queeg Nov 14 '21 at 22:25