How to restrict the users that can run jenkinsfile tests in pull requests? How to restrict the users that can run jenkinsfile tests in pull requests? jenkins jenkins

How to restrict the users that can run jenkinsfile tests in pull requests?


please try adding these lines in your pipeline script:

node('slaveName') {    properties([            parameters([                    string(                            defaultValue: 'whitelisted1@gmail.com,whitelisted2@gmail.com',                            description: 'comma separated whitelisted emails',                            name: 'WHITELIST'                    )            ])    ])    def authorEmail        stage('Git') {            authorEmail = sh([                    // git log format docs here: https://git-scm.com/docs/pretty-formats                    script      : "git log -1 --format='%aE'",                    returnStdout: true            ]).trim()            boolean allowRun = isWhitelisted(env.WHITELIST, authorEmail)            if (allowRun) {                echo "email ${authorEmail} is whitelisted, proceed execution"            } else {                echo "email ${authorEmail} is not in whitelist ${env.WHITELIST}, proceed jenkins job?"                input message: 'Proceed?'                // or just abort build with non-zero shell exit                // currentBuild.result = 'FAILURE'                // sh "exit 10"            }        }    }}@NonCPSboolean isWhitelisted(whitelist, email) {    def res = whitelist.tokenize(" ,;").find { white -> white == email }    return null != res}