View Pyenv Pipeline on the plugin site for more information.
A Jenkins plugin that provides a way to execute
bat Pipeline DSL commands within a specified Python virtualenv.
Why did you make this?
bat steps in the Jenkinsfile Pipeline DSL reset environmental information after every execution. For simple environmental variable needs, one can simply utilize the
withEnv step, and execute the commands as needed within the block. The Python virtualenv, however, requires a fairly complicated set of environmental steps, and it is much easier and more reliable to fallback on the behavior of the virtualenv project. However, for this to work, a
bat command to be executed within the virtualenv must be prefiex with a command that first activates the virtualenv; for every single command to be ran within the virtualenv. This is verbose, repetitive and error-prone.
This plugin provides 1 new Pipeline DSL method:
withPythonEnv: Specifies a Python virtualenv to execute any
batDSL commands contained within its block.
withPythonEnvtakes a single String argument, which specifies the Python executable to use for the virtualenv. pyenv-pipeline will use the executable to generate a corresponding virtualenv. At runtime, it will take a snapshot of environmental variables with and without the virtualenv active. From this it generates a diff, and applies the environmental variable changes within the
withPythonEnvblock (reverting them after the block completes)
The argument provided to
withPythonEnvwill first attempt to match it against the name of a
ToolInstallationthat is described by a
ToolDescriptorwith an ID that is contained within a pre-defined list of known Jenkins Python Tool plugin IDs. Currently, this plugin only looks to see if ShiningPanda is installed. If a
ToolInstallationis matched, the location of that tool is used as the Python executable to generate the virtualenv.
ToolInstallationis matched, then the argument is treated as the literal location of the Python executable to be used. This can be used to specify a specific Python installation (if the location is known beforehand), or to fallback and use the systems default Python installation.
withPythonEnvis called with an argument for the first time, it creates the virtualenv needed. Whenever
withPythonEnvis called with the same argument, the previously created virtualenv is used again.