-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathJenkinsfile
48 lines (43 loc) · 1.41 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
pipeline {
environment {
GITLAB_CREDENTIAL_ID = 'gitlab-registry-id'
PROJECT_PATH = 'trancport/blockchain/ashswap/ash-landing-page'
ENV = 'mainnet'
DOCKER_CONTEXT = '.'
DOCKERFILE = 'Dockerfile'
IMAGE_LATEST_TAG = 'latest'
}
agent {
node {
label 'base'
}
}
stages {
stage ('Checkout SCM') {
steps {
checkout(scm)
sh 'git tag --points-at HEAD --sort -version:refname | head -1 > GIT_TAG'
script {
gitTag = readFile('GIT_TAG').trim()
}
}
}
stage('Build & push') {
when {
expression {
sh([returnStdout: true, script: "echo ${gitTag} | tr -d '\n'"])
}
}
steps {
container('base') {
sh 'printenv'
sh "docker build -t registry.gitlab.com/${PROJECT_PATH}:${gitTag} -t registry.gitlab.com/${PROJECT_PATH}:${IMAGE_LATEST_TAG} ${DOCKER_CONTEXT} --build-arg ENV=${ENV} -f ${DOCKERFILE}"
withCredentials([usernamePassword(credentialsId : "$GITLAB_CREDENTIAL_ID" ,passwordVariable : 'REGISTRY_PASSWORD' ,usernameVariable : 'REGISTRY_USERNAME' ,)]) {
sh 'echo "$REGISTRY_PASSWORD" | docker login registry.gitlab.com -u "$REGISTRY_USERNAME" --password-stdin'
sh "docker push registry.gitlab.com/${PROJECT_PATH}:${gitTag} && docker push registry.gitlab.com/${PROJECT_PATH}:${IMAGE_LATEST_TAG}"
}
}
}
}
}
}