-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
executable file
·85 lines (76 loc) · 3.01 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
#!groovy
// Global scope required for multi-stage persistence
def artServer = Artifactory.server "art-p-01"
def buildInfo = Artifactory.newBuildInfo()
def agentPython3Version = 'python_3.10'
def pushToPyPiArtifactoryRepo(String projectName, String sourceDist = 'dist/*', String artifactoryHost = 'art-p-01') {
withCredentials([usernamePassword(credentialsId: env.ARTIFACTORY_CREDS, usernameVariable: 'ARTIFACTORY_USER', passwordVariable: 'ARTIFACTORY_PASSWORD')]){
sh "curl -u ${ARTIFACTORY_USER}:\${ARTIFACTORY_PASSWORD} -T ${sourceDist} 'http://${artifactoryHost}/artifactory/${env.ARTIFACTORY_PYPI_REPO}/${projectName}/'"
}
}
pipeline {
libraries {
// Useful library from ONS internal GitLab
lib('jenkins-pipeline-shared')
}
// Define environment variables
environment {
PROJECT_NAME = "mbs_results"
MAIN_BRANCH = "main"
PROXY = credentials("PROXY") // Http proxy address, set in Jenkins Credentials
ARTIFACTORY_CREDS = "ARTIFACTORY_CREDENTIALS"
ARTIFACTORY_PYPI_REPO = "LR_mbs-results"
BUILD_BRANCH = "main" // only deploy from this/these branches
BUILD_TAG = "v*.*.*" // only deploy with a commit message tagged like v0.0.1
}
// Don't use default checkout process, as we define it as a stage below
options {
skipDefaultCheckout true
}
// Agent must always be set at the top level of the pipeline
agent any
stages {
stage("Checkout") {
// We have to specify an appropriate slave for each stage
// Choose from download, build, test, deploy
agent { label "download.jenkins.slave" }
steps {
colourText("info", "Checking out code from source control.")
checkout scm
script {
buildInfo.name = "${PROJECT_NAME}"
buildInfo.number = "${BUILD_NUMBER}"
buildInfo.env.collect()
}
// Stash the files that have been checked out, for use in subsequent stages
stash name: "Checkout", useDefaultExcludes: false
}
}
stage("Build") {
agent { label "build.${agentPython3Version}" }
steps {
unstash name: 'Checkout'
colourText('info', "Building package")
sh 'pip3 install setuptools'
sh 'pip3 install wheel'
sh 'python3 setup.py build bdist_wheel'
stash name: "Build", useDefaultExcludes: false
}
}
stage("Deploy") {
when {
anyOf{
branch BUILD_BRANCH
tag BUILD_TAG
}
beforeAgent true
}
agent { label "deploy.jenkins.slave" }
steps {
unstash name: "Build"
colourText('info', "Deploying to Artifactory")
pushToPyPiArtifactoryRepo("${buildInfo.name}")
}
}
}
}