我有一個 Jenkins 管道,可以通過不同的環境進行一些代碼檢查。我有一個基于傳遞的引數呼叫的 linting 方法。但是,在我的構建程序中,呼叫該方法的階段什么也不做,也不回傳任何內容。一切對我來說似乎都是理智的。下面是我的代碼,以及顯示空結果的階段。
Jenkinsfile:
IAMMap = [
"west": [
account: "XXXXXXXX",
],
"east": [
account: "YYYYYYYYY",
],
]
pipeline {
options {
ansiColor('xterm')
}
parameters {
booleanParam(
name: 'WEST',
description: 'Whether to lint code from west account or not. Defaults to "false"',
defaultValue: false
)
booleanParam(
name: 'EAST',
description: 'Whether to lint code from east account or not. Defaults to "false"',
defaultValue: true
)
booleanParam(
name: 'LINT',
description: 'Whether to perform linting. This should always default to "true"',
defaultValue: true
)
}
environment {
CODE_DIR = "/code"
}
stages {
stage('Start Lint') {
steps {
script {
if (params.WEST && params.LINT) {
codeLint("west")
}
if (params.EAST && params.LINT) {
codeLint("east")
}
}
}
}
}
post {
always {
cleanWs disableDeferredWipeout: true, deleteDirs: true
}
}
}
def codeLint(account) {
return {
stage('Code Lint') {
dir(env.CODE_DIR) {
withAWS(IAMMap[account]) {
sh script: "./lint.sh"
}
}
}
}
}
Results:
15:00:20 [Pipeline] { (Start Lint)
15:00:20 [Pipeline] script
15:00:20 [Pipeline] {
15:00:20 [Pipeline] }
15:00:20 [Pipeline] // script
15:00:20 [Pipeline] }
15:00:20 [Pipeline] // stage
15:00:20 [Pipeline] stage
15:00:20 [Pipeline] { (Declarative: Post Actions)
15:00:20 [Pipeline] cleanWs
15:00:20 [WS-CLEANUP] Deleting project workspace...
15:00:20 [WS-CLEANUP] Deferred wipeout is disabled by the job configuration...
15:00:20 [WS-CLEANUP] done
如您所見,沒有任何內容被執行。Build with Parameters我向您保證,在控制臺中運行時,我正在檢查所需的引數。據我所知,這是宣告性管道的正確語法。
uj5u.com熱心網友回復:
不要回傳舞臺,只需在codeLint函式內執行它。
def codeLint(account) {
stage('Code Lint') {
dir(env.CODE_DIR) {
withAWS(IAMMap[account]) {
sh script: "./lint.sh"
}
}
}
}
或者,一旦舞臺回傳,您就可以運行它。這可能需要腳本批準。
codeLint("west").run()
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/523009.html
標籤:詹金斯时髦的詹金斯管道
上一篇:如何將django'models.py'、'views.py'、'serializers.py'檔案拆分為多個檔案
