Skip to content

Commit 7d0a45a

Browse files
test: build docker image (elastic#17905)
* feat: push docker images * fix: retrict a little the changes that trigger a full build * fix: restore use of gitcheckout * Update .ci/packaging.groovy
1 parent 3711ee6 commit 7d0a45a

2 files changed

Lines changed: 47 additions & 7 deletions

File tree

.ci/packaging.groovy

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,51 @@ pipeline {
125125
}
126126

127127
def pushCIDockerImages(){
128-
sh(label: 'Push Docker image', script: '''
129-
if [ -n "$(command -v docker)" ]; then
130-
docker images || true
131-
fi
132-
''')
128+
catchError(buildResult: 'UNSTABLE', message: 'Unable to push Docker images', stageResult: 'FAILURE') {
129+
if ("${env.BEATS_FOLDER}" == "auditbeat"){
130+
tagAndPush('auditbeat-oss')
131+
} else if ("${env.BEATS_FOLDER}" == "filebeat") {
132+
tagAndPush('filebeat-oss')
133+
} else if ("${env.BEATS_FOLDER}" == "heartbeat"){
134+
tagAndPush('heartbeat')
135+
tagAndPush('heartbeat-oss')
136+
} else if ("${env.BEATS_FOLDER}" == "journalbeat"){
137+
tagAndPush('journalbeat')
138+
tagAndPush('journalbeat-oss')
139+
} else if ("${env.BEATS_FOLDER}" == "metricbeat"){
140+
tagAndPush('metricbeat-oss')
141+
} else if ("${env.BEATS_FOLDER}" == "packetbeat"){
142+
tagAndPush('packetbeat')
143+
tagAndPush('packetbeat-oss')
144+
} else if ("${env.BEATS_FOLDER}" == "x-pack/auditbeat"){
145+
tagAndPush('auditbeat')
146+
} else if ("${env.BEATS_FOLDER}" == "x-pack/elastic-agent") {
147+
tagAndPush('elastic-agent')
148+
} else if ("${env.BEATS_FOLDER}" == "x-pack/filebeat"){
149+
tagAndPush('filebeat')
150+
} else if ("${env.BEATS_FOLDER}" == "x-pack/metricbeat"){
151+
tagAndPush('metricbeat')
152+
}
153+
}
154+
}
155+
156+
def tagAndPush(name){
157+
def libbetaVer = sh(label: 'Get libbeat version', script: 'grep defaultBeatVersion ${BASE_DIR}/libbeat/version/version.go|cut -d "=" -f 2|tr -d \\"', returnStdout: true)?.trim()
158+
if("${env.SNAPSHOT}" == "true"){
159+
libbetaVer += "-SNAPSHOT"
160+
}
161+
def oldName = "${DOCKER_REGISTRY}/beats/${name}:${libbetaVer}"
162+
def newName = "${DOCKER_REGISTRY}/observability-ci/${name}:${libbetaVer}"
163+
def commitName = "${DOCKER_REGISTRY}/observability-ci/${name}:${env.GIT_BASE_COMMIT}"
164+
dockerLogin(secret: "${DOCKERELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
165+
retry(3){
166+
sh(label:'Change tag and push', script: """
167+
docker tag ${oldName} ${newName}
168+
docker push ${newName}
169+
docker tag ${oldName} ${commitName}
170+
docker push ${commitName}
171+
""")
172+
}
133173
}
134174

135175
def release(){

Jenkinsfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ def isChangedOSSCode(patterns) {
918918
"^libbeat/.*",
919919
"^testing/.*",
920920
"^dev-tools/.*",
921-
"^\\.ci/.*",
921+
"^\\.ci/scripts/.*",
922922
]
923923
allPatterns.addAll(patterns)
924924
return isChanged(allPatterns)
@@ -932,7 +932,7 @@ def isChangedXPackCode(patterns) {
932932
"^dev-tools/.*",
933933
"^testing/.*",
934934
"^x-pack/libbeat/.*",
935-
"^\\.ci/.*",
935+
"^\\.ci/scripts/.*",
936936
]
937937
allPatterns.addAll(patterns)
938938
return isChanged(allPatterns)

0 commit comments

Comments
 (0)