由于我的專案依賴于 Rust,我想安裝它。我的 Jenkinsfile 看起來像這樣:
pipeline {
agent any
stages {
stage('Linting') {
steps {
echo 'Linting...'
sh "python3 -m pip install --upgrade pip --user"
}
}
stage('Build') {
steps {
echo 'Building...'
sh "python3 -m pip install --upgrade build --user"
sh "python3 -m build"
}
}
stage('Publish') {
steps {
echo 'Publishing...'
sh "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"
sh "source $HOME/.cargo/env"
sh 'export PATH="$HOME/.cargo/bin:$PATH"'
sh "rustc --version"
}
}
}
}
執行時,管道產生:rustc: command not found.
Jenkins 環境是否有一種特殊的方式來處理環境變數或專門處理環境變數$HOME?
uj5u.com熱心網友回復:
正如 Jmb 提到的,這可能是由于您執行 sh 塊的方式。相反,您可以在同一個 sh 塊中使用多行字串。
steps {
echo 'Publishing...'
sh """
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
export PATH=$HOME/.cargo/bin:$PATH
rustc --version
"""
}
或者你可以sh用一個塊包裹你的withEnv塊。
withEnv(["PATH RUST=$HOME/.cargo/bin"]) {
sh "rustc --version"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/497281.html
