forked from opensearch-project/opensearch-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-copy.jenkinsfile
75 lines (74 loc) · 2.97 KB
/
docker-copy.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
lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))
pipeline {
options {
timeout(time: 30)
}
agent none
parameters {
choice(
name: 'SOURCE_IMAGE_REGISTRY',
choices: ['opensearchstaging', 'public.ecr.aws/opensearchstaging', 'opensearchproject', 'public.ecr.aws/opensearchproject', 'public.ecr.aws/t2m2d0w1'],
description: 'Choose the source image registry'
)
string(
name: 'SOURCE_IMAGE',
description: 'Image name and tag <IMAGE_NAME>:<IMAGE_TAG> Eg: opensearch:1.3.2',
trim: true
)
choice(
name: 'DESTINATION_IMAGE_REGISTRY',
choices: ['opensearchstaging', 'public.ecr.aws/opensearchstaging', 'opensearchproject', 'public.ecr.aws/opensearchproject'],
description: 'Choose the destination image registry'
)
string(
name: 'DESTINATION_IMAGE',
description: 'Image name and tag <IMAGE_NAME>:<IMAGE_TAG> Eg: opensearch:1.3.2',
trim: true
)
}
stages {
stage("Image Copy") {
agent {
docker {
label 'Jenkins-Agent-AL2-X64-C54xlarge-Docker-Host'
image 'opensearchstaging/ci-runner:ubuntu2004-x64-docker-buildx0.6.3-qemu5.0-awscli1.22-jdk11-v2'
args '-u root -v /var/run/docker.sock:/var/run/docker.sock'
alwaysPull true
}
}
stages {
stage('Parameters Check') {
steps {
script {
currentBuild.description = "${SOURCE_IMAGE_REGISTRY}/${SOURCE_IMAGE} to ${DESTINATION_IMAGE_REGISTRY}/${DESTINATION_IMAGE}"
if( SOURCE_IMAGE.isEmpty() || DESTINATION_IMAGE.isEmpty()) {
currentBuild.result = 'ABORTED'
error('Make sure all the parameters are passed in.')
}
}
}
}
stage('Copy Image to ECR/DockerHub') {
steps {
script {
copyContainer(
sourceImage: "${SOURCE_IMAGE}",
sourceRegistry: "${SOURCE_IMAGE_REGISTRY}",
destinationImage: "${DESTINATION_IMAGE}",
destinationRegistry: "${DESTINATION_IMAGE_REGISTRY}"
)
}
}
}
}
post() {
always {
script {
postCleanup()
sh "docker logout ${DESTINATION_IMAGE_REGISTRY} && docker image prune -f --all"
}
}
}
}
}
}