-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
71 lines (66 loc) · 2.85 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
pipeline {
agent any
environment {
DOCKER_CONFIG = "${env.WORKSPACE}/.docker"
DOCKER_REGISTRY = '009543623063.dkr.ecr.eu-west-2.amazonaws.com'
// DOCKER_IMAGE_NAME = "${env.JOB_NAME.split('/')[-2]?.replaceFirst('docker-', '')}"
DOCKER_IMAGE_NAME="docker-aws-xray-test"
DOCKER_TAG = "${env.BRANCH_NAME == 'master' ? 'latest' : env.BRANCH_NAME}"
DOCKER_OPTS = '--pull --compress --no-cache=true --force-rm=true --progress=plain '
DOCKER_BUILDKIT = '1'
AWS_REGION = 'eu-west-2'
BRANCH_NAME = 'develop'
ECR_REPO = '009543623063.dkr.ecr.eu-west-2.amazonaws.com/jenkins-gradle-ci'
AWS_CREDENTIALS_ID = 'aws-jenkins-service-account-credentials' // ID for AWS credentials in Jenkins
}
triggers {
upstream(upstreamProjects: 'Docker/docker-amazonlinux/2')
}
options {
ansiColor('xterm')
timestamps()
buildDiscarder(logRotator(numToKeepStr: '5'))
disableConcurrentBuilds()
}
stages {
stage('Authenticate to ECR') {
steps {
withCredentials([aws(credentialsId: "${AWS_CREDENTIALS_ID}", accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY')]) {
script {
def AWS_PASSWORD = sh(script: "aws ecr get-login-password --region ${AWS_REGION}", returnStdout: true).trim()
sh "echo ${AWS_PASSWORD} | docker login --username AWS --password-stdin 009543623063.dkr.ecr.${AWS_REGION}.amazonaws.com"
}
}
}
}
stage('Initialise') {
agent {
docker {
image '009543623063.dkr.ecr.eu-west-2.amazonaws.com/jenkins-docker-ci'
alwaysPull true
args '-v /var/run/docker.sock:/var/run/docker.sock'
}
}
steps {
script {
def workspaceDir = sh(script: 'pwd', returnStdout: true).trim()
echo "Current working directory: ${workspaceDir}"
}
}
}
stage('build') {
steps {
sh '''
docker build ${DOCKER_OPTS} -t "${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:${DOCKER_TAG}" .
'''
}
}
stage('publish') {
steps {
sh '''
docker push ${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:${DOCKER_TAG}
'''
}
}
}
}