我想讓我的種子工作儘可能小,並將所有邏輯保存在中央git存儲庫中。此外,我有幾個獨立的Jenkins實例,然後可以共享代碼。如何在Jenkins Job DSL腳本中加載Groovy庫?Jenkins Job DSL - 從git repo加載groovy庫
是否有像Pipeline Remote File Loader Plugin這樣的東西,所以你只需要做fileLoader.fromGit('lib.groovy', 'https://git.repo')
?
我想讓我的種子工作儘可能小,並將所有邏輯保存在中央git存儲庫中。此外,我有幾個獨立的Jenkins實例,然後可以共享代碼。如何在Jenkins Job DSL腳本中加載Groovy庫?Jenkins Job DSL - 從git repo加載groovy庫
是否有像Pipeline Remote File Loader Plugin這樣的東西,所以你只需要做fileLoader.fromGit('lib.groovy', 'https://git.repo')
?
此後我對從git.repo在參數化流水線作業實現這一目標, 使用管道腳本SCM的Quicksheet
可能是什麼你的興趣:
stash/unstash
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}"
的Job DSL Gradle Example展示瞭如何保持DSL代碼在一個Git倉庫。