2017-04-11 102 views

回答

0

此後我對從git.repo在參數化流水線作業實現這一目標, 使用管道腳本SCM的Quicksheet

可能是什麼你的興趣:

  • 裝載mecanism:stash/unstash
  • 「來自SCM」的
  • 位置:src = "../${env.JOB_NAME}@script/"

個詹金斯

Pipeline 
    Definition:  "Pipeline script from SCM" 
    SCM:    Git 
    Repository URL  git.repo 
    Branches to build */master 
    Script Path  jobs/build.groovy 
This project is parameterized: 
    String Parameter PARAM0 
    String Parameter PARAM1 

git.repo

├── jobs 
│ ├── helpers 
│ │ └── utils.groovy 
│ └── build.groovy 
└── scripts 
    ├── build 
    │ └── do_build.sh 
    └── inc.sh 

內容:utils.groovy

├── jobs 
│ ├── helpers 
│ │ └── utils.groovy 
def log(msg) { 
    println("========== " + msg) 
} 
return this 

內容:build.groovy

├── jobs 
│ └── build.groovy 
stage ('Init') { 
    /* Loads */ 
    def src     = "../${env.JOB_NAME}@script/" 
    def helpers_dir   = 'jobs/helpers' 
    def scripts_dir   = 'scripts' 
    /* Stages Scripts */ 
    def do_build   = 'build/do_build.sh' 
    utils     = load src + helpers_dir + "/utils.groovy" 
    dir(src) { 
     stash name: scripts_dir, includes: "${scripts_dir}/" 
    } 
} 
stage ('Build') { 
    node() { 
     unstash scripts_dir 
     build_return = sh (returnStdout: true, script: """ 
      ./${scripts_dir}/${do_build} \ 
      "${PARAM0}" \ 
      "${PARAM1}" 
     """).readLines() 
     builded = build_return.get(build_return.size()-1).tokenize(',') 
     utils.log("PARAM0: " + builded[0]) 
     utils.log("PARAM1: " + builded[1]) 
    } 
} 

項內容:inc.sh

└── scripts 
    └── inc.sh 
#!/bin/sh 
## scripts common includes 
common=included 

內容:do_build.sh

└── scripts 
    ├── build 
    │ └── do_build.sh 
#!/bin/sh 
## includes 
. $(dirname $(dirname ${0}))/inc.sh 
echo ${common} 
## ${0} : PARAM0 
## ${1} : PARAM1 
echo "${0},${1}" 
相關問題