-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_Jenkinsfile
More file actions
38 lines (38 loc) · 1.94 KB
/
_Jenkinsfile
File metadata and controls
38 lines (38 loc) · 1.94 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
pipeline {
agent any
stages {
stage('BUILD') {
steps {
withDockerRegistry(credentialsId: 'acr_creds', url: 'https://devops2022.azurecr.io/v2/') {
sh "docker build -t devops2022.azurecr.io/anisbook:$GIT_COMMIT ."
sh "docker push devops2022.azurecr.io/anisbook:$GIT_COMMIT"
sh "docker rmi devops2022.azurecr.io/anisbook:$GIT_COMMIT"
}
}
}
stage('TEST') {
steps {
script {
def imageTag = "anisbook:$GIT_COMMIT"
def acrLoginServer = "devops2022.azurecr.io"
def imageExists = sh(script: "set +x curl -fL ${acrLoginServer}/v2/manifests/${imageTag}", returnStatus: true) == 0
if (!imageExists) {
error("The image ${imageTag} was not found in the registry ${acrLoginServer}")
}
}
}
}
stage('DEPLOY') {
steps {
checkout([$class: 'GitSCM', branches: [[name: '*/main']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '2eb747c4-f19f-4601-ab83-359462e62482', url: 'https://github.com/Brights-DevOps-2022-Script/argocd.git']]])
withCredentials([usernamePassword(credentialsId: '2eb747c4-f19f-4601-ab83-359462e62482', passwordVariable: 'GIT_PASSWORD', usernameVariable: 'GIT_USERNAME')])
{
sh "sed -i 's|image:.*|image: devops2022.azurecr.io/nginxanisbook:${GIT_COMMIT}|' anis-argocd/deployment.yml"
sh("git add anis-argocd/deployment.yml")
sh("git commit -m 'update image'")
sh("git push https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/Brights-DevOps-2022-Script/argocd.git HEAD:main")
}
}
}
}
}