2016-07-06 33 views
6

我已經部署了管道代碼docker demo with multibranch如何限制可以在拉取請求中運行jenkinsfile測試的用戶?

它工作正常。我在組織中添加了我的github用戶名,當我提出pull請求時,運行測試。

但是,當其他用戶發出拉取請求時,他們的測試也會運行。我想要手動批准來自外部貢獻者的哪些請求很適合在我的jenkins服務器上運行。有沒有辦法做到這一點?

我可以用ghprb來實現,但它與管道不兼容,我想將我的作業遷移到管道。

+0

我相信這種使用情況下應該由https://wiki.jenkins.io/display/JENKINS/GitHub+Branch+Source+Plugin來解決現在。 – mkobit

回答

-2

請嘗試在您的管道腳本文件,添加這些行:

node('slaveName') { 

    properties([ 
      parameters([ 
        string(
          defaultValue: '[email protected],[email protected]', 
          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" 
      } 

     } 
    } 
} 

@NonCPS 
boolean isWhitelisted(whitelist, email) { 
    def res = whitelist.tokenize(" ,;").find { white -> white == email } 
    return null != res 
} 
+2

這不安全。在提交時,您可以輕鬆使用任何您想要的電子郵件,更不用說他們可以完全在其分支中更改Jenkinsfile以繞過此檢查。 –

+0

也許你是對的。但它真的有什麼意義:限制更改Jenkinsfile的人允許更改您的代碼的人? – ludenus

+1

這個問題是關於GitHub上的pull請求。拉請求作者不一定被允許改變你的代碼。 –

相關問題