簡體   English   中英

如何將參數傳遞給DSL中的管道作業

[英]How to pass paramaters to a pipelineJob in DSL

我有非常相似的管道作業,只是參數不同。 目的是通過在DSL腳本中傳遞參數而無需任何代碼重復來創建這些作業。

我關注了這篇文章 因此,如果在實現了本文中提到的步驟之后運行下面的DSL腳本,我的腳本就可以運行。

TL; DR在那篇文章中添加了一個共享庫,並且讓Jenkinsfile使用該共享庫。

我有一個非常相似的方法。 區別在於我想通過DSL創建構建作業,並通過DSL上的設置更改Jenkinsfile的默認參數。

問題是如何在Jenkinsfile中傳遞/覆蓋參數。

// BTW I'll run this code below in a loop. Open for any suggesstion 
pipelineJob('AwesomeBild') {

    description("A pipeline created by dsl")

    definition {
        cpsScm {
            scm {
                git {
                    remote { url('https://github.com/jalogut/jenkinsfile-shared-library-sample.git') }
                    branches('master')
                    // how can I pass params to the file
                    scriptPath('Jenkinsfile')
                    extensions { }
                }
            }
        }
    }
}

編輯

參數效果很好。 這是DSL文件的最新版本。

pipelineJob('AwesomeBild') {

    description("A pipeline created by dsl")


    parameters {
        stringParam( "key", "value" )
    }

    definition {
        cpsScm {
            scm {
                git {
                    remote { url('https://github.com/jalogut/jenkinsfile-shared-library-sample.git') }
                    branches('master')
                    // how can I pass params to the file
                    scriptPath('Jenkinsfile')
                    extensions { }
                }
            }
        }
    }
}

解決方案很簡單:只需使用$ key,但請保留單引號:

scriptPath('Jenkinsfile$key')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM