Search code examples
linuxjenkinscookiecutter

Cannot run cookiecutter after installing with pip in jenkins


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?


Solution

  • 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
                         '''
                    }