Since my project has a dependency on Rust, I wanted to install it. My Jenkinsfile looks like this:
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"
}
}
}
}
When executed, the pipeline yields: rustc: command not found
.
Is there a special way the Jenkins environment handles environment variables or specifically $HOME
?
CodePudding user response:
As Jmb mentioned this could be due to the way you execute your sh blocks. Instead, you can use multiline strings in the same sh block.
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
"""
}
Or you can wrap your sh
block with a withEnv
block.
withEnv(["PATH RUST=$HOME/.cargo/bin"]) {
sh "rustc --version"
}