我正在使用 Jenkins 构建一个使用 poetry 的 python 包,下面是在 Jenkinsfile 上安装 poetry 的 stage 命令
stage('poetry'){
steps {
sh 'curl -sSL https://install.python-poetry.org | python3'
sh 'export PATH="$HOME/.local/bin:$PATH"'
sh 'poetry --version'
}
}
但我在构建过程中收到此输出错误
sh
+ curl -sSL https://install.python-poetry.org
+ python3
Retrieving Poetry metadata
The latest version (1.4.0) is already installed.
[Pipeline] sh
+ export PATH=/var/lib/jenkins/.local/bin:/var/lib/jenkins/workspace/retina3/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
+ PATH=/var/lib/jenkins/.local/bin:/var/lib/jenkins/workspace/retina3/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
[Pipeline] sh
+ poetry --version
/var/lib/jenkins/workspace/retina3@tmp/durable-deb083f7/script.sh: line 1: poetry: command not found
可能出了什么问题?
答案1
每个sh
命令都会启动自己的 shell 会话。因此,您在一个会话中设置的任何变量都不会在另一个会话中可用。而是在同一个会话中设置变量并执行命令。
sh 'export PATH="$HOME/.local/bin:$PATH"; poetry --version'