forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-build.jenkinsfile
More file actions
72 lines (72 loc) 路 3.15 KB
/
Copy pathdocker-build.jenkinsfile
File metadata and controls
72 lines (72 loc) 路 3.15 KB
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
pipeline {
options {
timeout(time: 5, 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: 'Example: cd docker/ci && bash build-image-multi-arch.sh -r <REPO_NAME> -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
)
}
stages {
stage('Parameters Check') {
steps {
script {
if(! DOCKER_BUILD_GIT_REPOSITORY.startsWith('https://github.com/opensearch-project/')) {
currentBuild.result = 'ABORTED'
error('The repository needs to be an opensearch-project repository')
}
}
}
}
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'
registryUrl 'https://public.ecr.aws/'
alwaysPull true
}
}
steps {
script {
echo 'The docker-build workflow will only push docker images to staging, please use docker-copy to move the image to other repositories'
checkout([$class: 'GitSCM', branches: [[name: "${DOCKER_BUILD_GIT_REPOSITORY_REFERENCE}" ]], userRemoteConfigs: [[url: "${DOCKER_BUILD_GIT_REPOSITORY}" ]]])
def CREDENTIAL_ID = "jenkins-staging-dockerhub-credential"
sh "echo Account: $CREDENTIAL_ID"
withCredentials([usernamePassword(credentialsId: CREDENTIAL_ID, usernameVariable: 'DOCKER_USERNAME', passwordVariable: 'DOCKER_PASSWORD')]) {
sh '''
set -e
set +x
docker logout && echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin && eval $DOCKER_BUILD_SCRIPT_WITH_COMMANDS
'''
}
}
}
post() {
always {
script {
cleanWs disableDeferredWipeout: true, deleteDirs: true
sh "docker logout && docker image prune -f --all"
}
}
}
}
}
}