-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
140 lines (130 loc) · 4.89 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env groovy
def docker_credentials = 'ecr:us-east-1:tailor_aws'
def parentImage = { release, docker_registry -> docker_registry - "https://" + ':tailor-meta-' + release + '-parent-' + env.BRANCH_NAME }
def rosdistro_index = 'rosdistro/rosdistro/index.yaml'
def recipes_yaml = 'rosdistro/config/recipes.yaml'
pipeline {
agent none
parameters {
string(name: 'rosdistro_job', defaultValue: '/ci/toydistro/master')
string(name: 'release_track', defaultValue: 'hotdog')
string(name: 'release_label', defaultValue: 'hotdog')
string(name: 'num_to_keep', defaultValue: '10')
string(name: 'days_to_keep', defaultValue: '10')
string(name: 'docker_registry')
booleanParam(name: 'deploy', defaultValue: false)
}
options {
timestamps()
}
stages {
stage("Configure build parameters") {
agent { label 'master' }
steps {
script {
sh('env')
properties([
buildDiscarder(logRotator(
daysToKeepStr: params.days_to_keep, numToKeepStr: params.num_to_keep,
artifactDaysToKeepStr: params.days_to_keep, artifactNumToKeepStr: params.num_to_keep
))
])
copyArtifacts(
projectName: params.rosdistro_job,
selector: upstream(fallbackToLastSuccessful: true),
)
stash(name: 'rosdistro', includes: 'rosdistro/**')
}
}
post {
cleanup {
deleteDir()
}
}
}
stage("Build tailor-meta") {
agent any
steps {
script {
dir('tailor-meta') {
checkout(scm)
}
stash(name: 'source', includes: 'tailor-meta/**')
def parent_image_label = parentImage(params.release_label, params.docker_registry)
def parent_image = docker.image(parent_image_label)
try {
docker.withRegistry(params.docker_registry, docker_credentials) { parent_image.pull() }
} catch (all) {
echo("Unable to pull ${parent_image_label} as a build cache")
}
withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'tailor_aws']]) {
parent_image = docker.build(parent_image_label,
"-f tailor-meta/environment/Dockerfile --cache-from ${parent_image_label} " +
"--build-arg AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID " +
"--build-arg AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY .")
}
parent_image.inside() {
sh('pip3 install -e tailor-meta')
}
docker.withRegistry(params.docker_registry, docker_credentials) {
parent_image.push()
}
}
}
post {
cleanup {
library("tailor-meta@${params.tailor_meta}")
cleanDocker()
deleteDir()
}
}
}
stage("Update repositories") {
agent any
steps {
script {
def parent_image = docker.image(parentImage(params.release_label, params.docker_registry))
docker.withRegistry(params.docker_registry, docker_credentials) {
parent_image.pull()
}
def repositories = null
parent_image.inside() {
unstash(name: 'rosdistro')
withCredentials([string(credentialsId: 'tailor_github', variable: 'github_token')]) {
def repositories_yaml = sh(
script: "create_pipelines --rosdistro-index $rosdistro_index --recipes $recipes_yaml " +
"--github-key $github_token --meta-branch $env.BRANCH_NAME " +
"--release-track $params.release_track --release-label $params.release_label " +
"--rosdistro-job $params.rosdistro_job ${params.deploy ? '--deploy' : ''}",
returnStdout: true).trim()
sh(
script: "update_repo_settings --rosdistro-index $rosdistro_index --recipes $recipes_yaml " +
"--github-key $github_token ${params.deploy ? '--deploy' : ''} " +
"--release-track $params.release_track")
repositories = readYaml(text: repositories_yaml)
}
}
unstash(name: 'source')
if (params.deploy && params.release_track == 'hotdog') {
// Only manage jenkins jobs from master branch
jobDsl(
targets: 'tailor-meta/jobs/tailorTestJob.groovy',
removedJobAction: 'DELETE',
additionalParameters: [
'repositories': repositories,
'credentials_id': 'tailor_github_keypass',
// this extracts the (hopefully) unique job name: '/ci/rosdistro/master' -> 'rosdistro'
'folder_name': "test/${params.rosdistro_job.split('/')[-2]}",
]
)
}
}
}
post {
cleanup {
deleteDir()
}
}
}
}
}