forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-build.jenkinsfile
69 lines (69 loc) · 2.88 KB
/
docker-build.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
pipeline {
options {
timeout(time: 3, unit: 'HOURS')
}
agent none
parameters {
string(
defaultValue: 'https://github.com/opensearch-project/opensearch-build',
name: 'DOCKER_BUILD_GIT_REPOSITORY',
description: 'The git repository name that contains dockerfiles and the docker build script.',
trim: true
)
string(
defaultValue: 'main',
name: 'DOCKER_BUILD_GIT_REPOSITORY_REFERENCE',
description: 'The git reference (branch/tag/commit_id) of above repository.',
trim: true
)
string(
defaultValue: 'bash docker/ci/build-image-multi-arch.sh -v <TAG_NAME> -f <DOCKERFILE PATH>',
name: 'DOCKER_BUILD_SCRIPT_WITH_COMMANDS',
description: 'The script path of the docker build script, assuming you are already in root dir of DOCKER_BUILD_GIT_REPOSITORY.',
trim: true
)
booleanParam(
defaultValue: true,
name: 'IS_STAGING',
description: 'Are we pushing docker images to staging (opensearchstaging) or production (opensearchproject) account.'
)
}
stages {
stage('docker-build') {
agent {
docker {
label 'Jenkins-Agent-Ubuntu2004-X64-m52xlarge-Docker-Builder'
image 'opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.6.3-qemu5.0-awscli1.22-jdk14'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
alwaysPull true
}
}
steps {
script {
git url: "$DOCKER_BUILD_GIT_REPOSITORY", branch: "$DOCKER_BUILD_GIT_REPOSITORY_REFERENCE"
def CREDENTIAL_ID = "jenkins-staging-docker-staging-credential"
if (env.IS_STAGING == "false") {
CREDENTIAL_ID = "jenkins-staging-docker-prod-token"
sh "echo Switch to Production"
}
sh "echo Account: $CREDENTIAL_ID"
withCredentials([usernamePassword(credentialsId: CREDENTIAL_ID, usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh '''
set -ex
echo Login to $CREDENTIAL_ID
docker logout && docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD && eval $DOCKER_BUILD_SCRIPT_WITH_COMMANDS
'''
}
}
}
post() {
always {
script {
cleanWs disableDeferredWipeout: true, deleteDirs: true
sh "docker logout && docker image prune -f --all"
}
}
}
}
}
}