-
Notifications
You must be signed in to change notification settings - Fork 35
/
Jenkinsfile
118 lines (111 loc) · 4.16 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
pipeline {
environment {
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 = 'maestro-org'
ECH_REPO = 'sastre-pro'
GEN_USER = "cx-sastre-user.gen"
ECH_PATH = "${REGISTRY}/${ECH_ORG}/${ECH_REPO}"
ECH_CREDENTIALS = 'sastre-ech-token'
}
agent {
label "sastre-pro-node"
}
options { timestamps () }
stages {
stage('Log Build Info') {
steps {
script {
def hostname = sh(script: 'hostname', returnStdout: true).trim()
def ip = sh(script: 'hostname -I', returnStdout: true).trim()
def buildTriggerBy = currentBuild.getBuildCauses()[0].shortDescription
echo "Hostname: ${hostname}"
echo "IP: ${ip}"
echo "Build cause: ${buildTriggerBy}"
echo "Build number: ${env.BUILD_NUMBER}"
echo "Build URL: ${env.BUILD_URL}"
echo "Toolchain Information:"
echo "==== podman ===="
echo "podman: /usr/bin/podman"
sh "podman --version"
sh "sha256sum /usr/bin/podman"
}
}
}
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 {
withCredentials([conjurSecretCredential(credentialsId: "$ECH_CREDENTIALS", variable: "ECH_TOKEN")]) {
sh """
echo $ECH_TOKEN | docker login --username $GEN_USER --password-stdin containers.cisco.com
docker tag $ECH_PATH:$BRANCH_NAME $ECH_PATH:latest
docker push $ECH_PATH:latest
"""
}
echo "Generated Artifact Info:"
echo "Image name and version: $ECH_PATH:latest"
sh "docker inspect --format '{{.Digest}}' $ECH_PATH:latest"
echo "Stored in: $REGISTRY_URL"
sh "docker rmi $ECH_PATH:$BRANCH_NAME $ECH_PATH:latest"
}
when {
anyOf {
buildingTag()
branch pattern: "master|dev-.*", comparator: "REGEXP"
}
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
)
}