jenkinsci / pyenv-pipeline-plugin

Execute commands in Python virtualenvs in Jenkins Pipeline DSL
https://plugins.jenkins.io/pyenv-pipeline/
MIT License
33 stars 15 forks source link

Plugin can fail to use the correct environment when calling the binary python3 #37

Open Porkepix opened 4 years ago

Porkepix commented 4 years ago

We needed some times figuring it out, documentation shows that we can use the plugin this way:

withPythonEnv('python') {

}

So wishing to do the same, but by forcing the use of python 3 as the above example would hit python 2, I used

withPythonEnv('python3') {

}

But while the binary is correctly here and python3 command exist and poinbt to /usr/bin/python3, it caused errors and fails.

Calling the below example would however works.

withPythonEnv('/usr/bin/python3') {

}

python3 should be enough and not fail, nor require user to provide the full path to the binary.

cstarner commented 4 years ago

Can you show me the error output?

Porkepix commented 4 years ago

Sure, here are the relevant parts of some tests I did :

[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] ansiColor
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Create virtualenv and install dependencies)
[Pipeline] sh
+ which python3
/usr/bin/python3
[Pipeline] withPythonEnv
[Pipeline] {
[Pipeline] sh
+ which python3
/var/lib/jenkins/workspace/foo/.pyenv-usr-bin-python3/bin/python3

The first which is within a withPythonEnv('python3') { and hit the system python, the second one is within a withPythonEnv('/usr/bin/python3') {.

I could notice the issue as I was trying to do some pip install -r requirements.txt and there is no pip as system command, only within virtualenvironments, and so I just got errors like command not found.

elupus commented 1 year ago

Ran into this as well here. Took a long time to figure out what was going on since it silently fails to activate the environment.