[英]How to run shell script on Host from jenkins docker container?
[英]How to refer to shell script inside shared jenkins library
我有一個 Jenkinsfile,它使用共享的 Jenkins 庫並調用下面定義的 groovy 文件中的方法。
shared-jenkins-lib
|
|-----------vars
| |-------pipeline_script.groovy
|
|-----------scripts
|-------test_script.groovy
這是庫的結構和pipeline_script.groovy
有一個從 jenkinsfile 調用的方法test
。
def test(){
dockerArgs = "--entrypoint /bin/bash"
dockerCommand = "`../scripts/test_script.sh`"
dockerOut = sh (script: "docker run ${dockerArgs} ${image} ${dockerCommand}", returnStatus: true)
}
我參考了test_script.sh
但似乎沒有在該位置找到該文件。 我在 docker 中運行 jenkins。 引用腳本的正確方法是什么
如共享庫插件的文檔中所述,庫 repo 具有非常特定的結構。 repo 的根目錄可以有以下 3 個文件夾:
+- src # Groovy source files
| +- org
| +- foo
| +- Bar.groovy # for org.foo.Bar class
+- vars
| +- foo.groovy # for global 'foo' variable
| +- foo.txt # help for 'foo' variable
+- resources # resource files (external libraries only)
| +- org
| +- foo
| +- bar.json # static helper data for org.foo.Bar
如果你想從你的庫方法中引用一個幫助代碼/數據,你應該把它放在resources
目錄中,然后你可以使用libraryResource
步驟檢索它,也在文檔中描述。
您需要將工作流腳本 object 傳入test()
。
def test(workFlowScript wfs) {
...
wfs.sh ''
wfs.echo ''
wfs.withCredentials()
}
// your Jenkisnfile which call test()
test(this) // this is the instance of workFlowScript
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.