簡體   English   中英

從Jenkins Pipeline scrit看不到的環境變量

[英]Environment variable not seen from Jenkins Pipeline scrit

在“ 管理Jenkins ”->“ 配置系統 ”->“ 全局屬性 ”中,我添加了:

Name:  git
Value: /path/to/my/git

和:

Name: PATH+git
Value: /path/to/my/git

但是,如果我從Jenkins管道嘗試sh("git status") ,則會得到:

git: command not found

如果我嘗試使用完整路徑sh("/path/to/my/git status") ,則會看到git。

知道為什么在聲明為環境變量后為什么在Jenkins Pipeline腳本中看不到git嗎?

您必須在sh步驟中使用變量引用:

sh '$git status'

請注意單引號,這樣一來,groovy不會將$解釋為變量引用(將其保留給sh)。 如果使用雙引號,則必須轉義美元符號:

sh "\$git status"

或者您可以直接在groovy中訪問環境:

sh "${env.git} status"

暫無
暫無

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

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