Add python stage helper
This commit is contained in:
parent
d33eceddc2
commit
024a9798b3
13
README.md
Normal file
13
README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# pipelineUtils
|
||||||
|
|
||||||
|
This project is an attempt to provide a structured set of functions that can be used to create a pipeline library for the Jenkins CI/CD system.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Functions provided fall into several categories:
|
||||||
|
|
||||||
|
- "stage" helpers that implment a stage in the pipeline with particular behavior.
|
||||||
|
- "versioning" helpers that implement a particular strategy for versioning a project.
|
||||||
|
- "utiltity" functions that help with various things, such as printing banners in the job console log, incrementing a semantic version string, and adding git meta information to a pipeline's metadata.
|
||||||
|
|
||||||
|
## Example
|
||||||
51
vars/pythonVenvStage.groovy
Normal file
51
vars/pythonVenvStage.groovy
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
i
|
||||||
|
|
||||||
|
void call(Map config = [:], Closure body) {
|
||||||
|
defaultConfig = [
|
||||||
|
pythonPath: 'python3',
|
||||||
|
recreateVenv: false,
|
||||||
|
venvDir: '.venv',
|
||||||
|
updatePip: true,
|
||||||
|
installPipTools: true,
|
||||||
|
requirementsFile: 'requirements.in',
|
||||||
|
name: 'python'
|
||||||
|
]
|
||||||
|
runConfig = defaultConfig + config
|
||||||
|
|
||||||
|
venvDir = [
|
||||||
|
env.WORKSPACE,
|
||||||
|
runConfig.venvDir
|
||||||
|
]
|
||||||
|
venvBinDir = venvDir + 'bin'
|
||||||
|
venvPython = venvBinDir + 'python'
|
||||||
|
|
||||||
|
venvEnv = [
|
||||||
|
"VIRTUAL_ENV=${venvDir.join('/')}",
|
||||||
|
"PATH=${venvBinDir.join('/')}"
|
||||||
|
]
|
||||||
|
|
||||||
|
stage(runConfig.name) {
|
||||||
|
if (fileExists(runConfig.venvDir) && runConfig.recreateVenv) {
|
||||||
|
dir(runConfig.venvDir) {
|
||||||
|
deleteDir()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileExists(runConfig.venvDir)) {
|
||||||
|
sh "${runConfig.pythonPath} -m venv ${runConfig.venvDir}"
|
||||||
|
}
|
||||||
|
|
||||||
|
withEnv(venvEnv) {
|
||||||
|
if (runConfig.updatePip) {
|
||||||
|
sh "${venvPython} -m pip install --upgrade pip"
|
||||||
|
}
|
||||||
|
if (runConfig.installPipTools) {
|
||||||
|
sh "${venvPython} -m pip install pip-tools"
|
||||||
|
}
|
||||||
|
if (fileExists(runConfig.requirementsFile)) {
|
||||||
|
sh "pip-compile ${runConfig.requirementsFile}"
|
||||||
|
}
|
||||||
|
body()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user