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

persistent created venv between different steps #48

Open msegura501 opened 1 year ago

msegura501 commented 1 year ago

What feature do you want to see added?

Currently if we have a venv created in one step, it is not kept for subsequent steps execution. The subsequent step will create a new empty venv.

To reuse a venv between different steps, unstash / stash need to be used. For example :

def PYTHON='python3.8'
pipeline {
    stages {
        stage('Clean Jenkins workspace') {
            steps {
                deleteDir()
            }
        }
        stage('Install dep') {
            steps {
                withPythonEnv(PYTHON) {
                    sh 'python -m pip install --upgrade pip'
                    sh 'pip install ansible==6.4.0'
                    sh 'pip install openstacksdk==0.61.0'
                    stash includes: '.pyenv-'+PYTHON+'/', name: 'venv'
                }
            }
        }
        stage('Run playbook') {
            steps {
                git branch: 'main', url: 'https://somegit.repo/user/ansible-minimal-playbook.git'
                unstash 'venv'
                withPythonEnv(PYTHON) {
                    sh 'ansible-playbook playbook.yml'
                }
            }
        }
    }
}

In the above without the stash / unstash statements, the step Run playbook will fire in an empty venv where ansible has not been yet installed. Hence the pipeline will fail.

Would it be feasible to add a feature where a venv (with the same name) can be shared among multiple steps? What do you think?

Upstream changes

No response