Create resusable jenkins pipeline script

后端 未结 4 771
余生分开走
余生分开走 2021-01-31 09:08

I am considering to use Jenkins pipeline script recently, one question is that I don\'t figure out a smart to way to create internal reusable utils code, imagine, I have a commo

4条回答
  •  无人及你
    2021-01-31 09:56

    Here is the solution that we are currently using in order to re-use Jenkinsfile code:

    node {
    
      curl_cmd = "curl -H 'Accept: application/vnd.github.v3.raw' -H 'Authorization: token ${env.GITHUB_TOKEN}' https://raw.githubusercontent.com/example/foobar/master/shared/Jenkinsfile > Jenkinsfile.t
      sh "${curl_cmd}"
      load 'Jenkinsfile.tmp'
    
    }
    

    I might be a bit ugly but it works realiably and in addition to that it also allows us to insert some repository specific code before or after the shared code.

提交回复
热议问题