Im trying to install the cookiecutter utility using a jenkins pipeline. I try run this stage:
stage('Install CookieCutter') {
steps{
script {
sh'''
pip uninstall cookiecutter -y
export PATH=$HOME/.local/bin:$PATH
pip install --user cookiecutter
cookiecutter -V
'''
}
}
}
After running this stage i get the following output:
pip uninstall cookiecutter -y
Found existing installation: cookiecutter 1.7.3
Uninstalling cookiecutter-1.7.3:
Successfully uninstalled cookiecutter-1.7.3
export PATH=/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
PATH=/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin
pip install --user cookiecutter
Collecting cookiecutter
Using cached cookiecutter-1.7.3-py2.py3-none-any.whl (34 kB)
Requirement already satisfied: click>=7.0 in /root/.local/lib/python2.7/site-packages (from cookiecutter) (7.1.2)
Requirement already satisfied: six>=1.10 in /usr/local/lib/python2.7/site-packages (from cookiecutter) (1.16.0)
Installing collected packages: cookiecutter
WARNING: The script cookiecutter is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed cookiecutter-1.7.3
cookiecutter -V
/workspace/pipeline@tmp/durable-123456/script.sh: line 5: cookiecutter: command not found
I'm ignoring the pip version warning for now as i dont think this has anything to do with this not installing.
What is going wrong here?
CodePudding user response:
WARNING: The script cookiecutter is installed in '/root/.local/bin' which is not on PATH.
So, for some reason your export doesn't work. There may be two reasons for this:
- $HOME is not root, which I actually doubt
- This Jenkins script behaves like GNU Make. Each line is executed in a different subshell, so your export doesn't really count. Try to execute this as a one liner like this:
stage('Install CookieCutter') {
steps{
script {
sh'''
pip uninstall cookiecutter -y && \
export PATH=$HOME/.local/bin:$PATH && \
pip install --user cookiecutter && \
cookiecutter -V
'''
}
}
}
Or you can try just this instead as a more concise variant:
stage('Install CookieCutter') {
steps{
script {
sh'''
pip uninstall cookiecutter -y
pip install --user cookiecutter
PATH=$HOME/.local/bin:$PATH cookiecutter -V
'''
}
}
}
CodePudding user response:
Turns out the home directory was not defined properly so replaced $HOME
with ~
script {
sh'''
pip uninstall cookiecutter -y
source ~/.bash_profile
export PATH="~/.local/bin:$PATH"
pip install --user cookiecutter
ls ~/.local/bin
cookiecutter -V
'''
}