Jenkins restrict view of jobs per user

前端 未结 7 1397
萌比男神i
萌比男神i 2020-12-02 09:00

Is there a way to restrict user to view only certain jobs in Jenkins.

Jenkins allows the restriction of user ability per project via the \"Project-based Matrix Autho

7条回答
  •  自闭症患者
    2020-12-02 09:29

    I use combination of several plugins - for the basic assignment of roles and permission I use Role Strategy Plugin.

    When I need to split some role depending on parameters (e.g. everybody with job-runner is able to run jobs, but user only user UUU is allowed to run the deployment job to deploy on machine MMM), I use Python Plugin and define a python script as first build step and end with sys.exit(-1) when the job is forbidden to be run with the given combination of parameters.

    Build User Vars Plugin provides me the information about the user executing the job as environment variables.

    E.g:

    import os
    import sys
    
    print os.environ["BUILD_USER"], "deploying to", os.environ["target_host"]
    
    # only some users are allowed to deploy to servers "MMM"
    mmm_users = ["UUU"]
    
    if os.environ["target_host"] != "MMM" or os.environ["BUILD_USER"] in mmm_users:
        print "access granted"
    else:
        print "access denied"
        sys.exit(-1)
    

提交回复
热议问题