forked from CiscoDevNet/sastre
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
88 lines (85 loc) · 2.86 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
pipeline {
environment {
GIT_CREDS = credentials('345c79bc-9def-4981-94b5-d8190fdd2304') // as-ci-user.gen
WEBEX_ROOM = 'Y2lzY29zcGFyazovL3VzL1JPT00vZTMxNTUzZjAtZDNiMS0xMWViLWJjNzktMTUxMzcwZjZlOTYz' // Sastre - CICD Notifications
WEBEX_CREDS = '16fdd237-afe3-4d7f-9fe5-7bde6d1275e0' // sastre-cicd@webex.bot
REGISTRY = 'containers.cisco.com'
REGISTRY_URL = "https://$REGISTRY"
ECH_ORG = 'aide'
ECH_REPO = 'sastre-pro'
ECH_PATH = "${REGISTRY}/${ECH_ORG}/${ECH_REPO}"
ECH_CREDENTIALS = '70d73668-c133-45cc-9943-cc32f1830945'
}
agent {
label "AMER-REGION"
}
stages {
stage("Build") {
agent {
dockerfile {
additionalBuildArgs "-t $ECH_PATH:$BRANCH_NAME"
reuseNode true
}
}
steps {
echo "Building container..."
}
}
stage("Code Quality Test") {
steps {
echo "Quality test"
}
}
stage("Publish") {
options { skipDefaultCheckout true }
steps {
withDockerRegistry([ credentialsId: "$ECH_CREDENTIALS", url: "$REGISTRY_URL" ]) {
sh """
docker tag $ECH_PATH:$BRANCH_NAME $ECH_PATH:latest
docker push $ECH_PATH:latest
"""
}
}
when {
anyOf {
buildingTag()
branch 'master'
}
beforeAgent true
}
}
}
post {
always {
echo 'Cleanup'
}
success {
sendNotifications('success', WEBEX_ROOM, WEBEX_CREDS)
}
unstable {
sendNotifications('unstable', WEBEX_ROOM, WEBEX_CREDS)
}
failure {
sendNotifications('failure', WEBEX_ROOM, WEBEX_CREDS)
}
}
}
def sendNotifications(String status, String room, String creds) {
def GIT_COMMIT = sh (label: "Get git commit ID", script: "git rev-parse HEAD || true", returnStdout: true).trim()
def AUTHOR = sh (label: "Get git commit Author", script: "git show -s --pretty=\"%an <%ae>\" ${GIT_COMMIT} || true", returnStdout: true).trim()
if (status == 'success') {
icon = "✅"
} else {
icon = "❌"
}
msg = "${icon} **Build ${env.BUILD_ID} ${status}** <br/> **Jenkins Job**: [${env.JOB_NAME}](${env.BUILD_URL}) <br/> **Change Author**: ${AUTHOR} <br/> **Git Branch**: ${env.BRANCH_NAME} <br/> **Git Commit**: ${GIT_COMMIT} <br/> **GitHub URL**: ${GIT_URL} <br/>"
sparkSend (
credentialsId: creds,
failOnError: false,
messageType: 'markdown',
spaceList: [[
spaceId: room
]],
message: msg
)
}