I have a Jenkins multi-branch pipeline for building artifacts and there are branches for master
, *-dev
etc.
I want to enable project based security on a per branch basis, ie only allow devs to run the *-dev
branch jobs of the build not any other ones because doing so would have undesirable effects.
I know there is project based security, but I didn't see any per branch. Does this exist? We are behind in updating Jenkins and are currently running Jenkins 2.46.1
.
Otherwise I am thinking I might have to have a separate upstream job to call the correct branch of the downstream one and make the downstream artifact job unable to be run by devs with the privilege to do so. (This sounds like overkill).
Or is there any way to accomplish this in the branch's Jenkinsfile?
Here's some
Jenkinsfile
groovy that will get you close to what you want:Caveats:
jenkins_admins
group to which privileged users belong --- your user/groups situation may be very different.@NonCPS
-annotated functions --- you riskjava.io.NotSerializableException
otherwise.References: