-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
94 lines (92 loc) · 3.33 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
node ("python3") {
VERSION_STRING="$MAJOR_VERSION.$MINOR_VERSION.$BUILD_NUMBER"
def image = null
stage("Git Pull") {
// Get from github
git credentialsId: "github_pk", url: "[email protected]:martinnj/distro-dumper.git", branch: "main"
}
stage("Configure") {
// Set version in relevant files.
sh "sed -i 's/###VERSION###/$VERSION_STRING/g' setup.py"
sh "sed -i 's/###VERSION###/$VERSION_STRING/g' dumper.py"
sh "sed -i 's/###VERSION###/$VERSION_STRING/g' Dockerfile"
// Create dir to pick up analysis reports.
sh "mkdir reports"
}
stage("Static Analysis") {
withPythonEnv("/home/jenkins/.pyenv/shims/python3.9") {
sh "python --version"
sh "pip --version"
sh "pip install -r requirements-dev.txt"
sh "tox -e lint > reports/pylint.log || true"
// TODO: sh "tox -e typecheck"
// Publish pylint results.
def checkstyle = scanForIssues(
blameDisabled: true,
forensicsDisabled: true,
sourceDirectory: ".",
tool: pyLint(pattern: "reports/pylint.log")
)
publishIssues issues: [checkstyle]
}
}
stage("Testing") {
// TODO: This is really ugly. >_< I would love for "withPythonEnv" to discover pyenv itself.
parallel py39: {
withPythonEnv("/home/jenkins/.pyenv/shims/python3.9") {
sh "python --version && pip --version"
sh "pip install --upgrade pip \"tox<4.0.0\""
sh "tox -e cov"
// Publist test & coverage reports.
junit("reports/xunit.xml")
recordCoverage(tools: [[parser: 'COBERTURA', pattern: 'reports/cov.xml']])
}
}, py310: {
withPythonEnv("/home/jenkins/.pyenv/shims/python3.10") {
sh "python --version && pip --version"
sh "pip install --upgrade pip \"tox<4.0.0\""
sh "tox -e py310"
}
}, py311: {
withPythonEnv("/home/jenkins/.pyenv/shims/python3.11") {
sh "python --version && pip --version"
sh "pip install --upgrade pip \"tox<4.0.0\""
sh "tox -e py311"
}
}
}
stage("Tag") {
sshagent(["github_pk"]) {
sh "git tag -a v$VERSION_STRING -m \"Tagged by $BUILD_URL\""
sh "git push --tags"
}
}
stage("Stash") {
// Stash the files we need to build the Docker image.
stash(
name: "docker-application",
includes: ".dockerignore, Dockerfile, dumper.py, requirements.txt, distrodumper/**",
excludes: "__pycache__"
)
}
}
node("docker") {
stage("Unstash") {
// Unstash the Docker image requisites.
unstash(name: "docker-application")
}
stage("Build Docker Image") {
// When using the extra arguments, we need to apply the final arguments
// oursleves as well. Hence the " ." at the end.
image = docker.build("distro-dumper:$VERSION_STRING", "--no-cache -f Dockerfile .")
}
stage("Push") {
docker.withRegistry("$REGISTRY_URL") {
image.push()
image.push("latest")
}
}
stage("Clean") {
cleanWs()
}
}