-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfilek8s
170 lines (148 loc) · 5.34 KB
/
Jenkinsfilek8s
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Jenkinsfilek8s v1.2.0
pipeline {
agent {
kubernetes {
label 'pic18f47q10-cnano-spi-master-send-fs'
defaultContainer 'xc8-mplabx'
yamlFile 'cloudprovider.yml'
}
}
parameters {
string( name: 'NOTIFICATION_EMAIL',
defaultValue: 'PICAVR_Examples_GateKeepers@microchip.com',
description: "Email to send build failure and fixed notifications.")
}
environment {
GITHUB_OWNER = 'microchip-pic-avr-examples'
GITHUB_URL ='https://github.com/microchip-pic-avr-examples/pic18f47q10-cnano-spi-master-send-fs.git'
BITBUCKET_URL = 'https://bitbucket.microchip.com/scm/ebe/pic18f47q10-cnano-spi-master-send-fs.git'
DEPLOY_TOOL_URL = 'https://bitbucket.microchip.com/scm/citd/tool-github-deploy.git'
DEPLOY_SCRIPT_DIR = 'tool-github-deploy'
DEPLOY_SCRIPT_FILE = 'deploy-source-as-is.sh'
}
options {
timestamps()
timeout(time: 30, unit: 'MINUTES')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('metadata') {
steps {
script {
execute("pip install jsonschema")
execute("git clone https://bitbucket.microchip.com/scm/citd/metadata-schema.git")
execute("git clone https://bitbucket.microchip.com/scm/citd/tool-metadata-validator.git")
execute("cd tool-metadata-validator && python metadata-validator.py -data '../.main-meta/main.json' -schema '../metadata-schema/main-schema.json'")
}
}
}
stage('Pre-build') {
steps {
script {
MPLABX_PATH= sh (script: 'update-alternatives --list MPLABX_PATH',returnStdout: true).trim()
COMPILER_PATH= sh (script: 'update-alternatives --list XC8_PATH',returnStdout: true).trim()
def pDir = "${MPLABX_PATH}/packs"
def ver = COMPILER_PATH.split('/')[4].substring(1)
execute("git clone https://bitbucket.microchip.com/scm/citd/tool-mplabx-c-project-generator.git")
execute("cd tool-mplabx-c-project-generator && node configGenerator.js sp=../ v8=${ver} packs=${pDir}")
}
}
}
stage('Build') {
steps {
script {
execute("git clone https://bitbucket.microchip.com/scm/citd/tool-mplabx-c-build.git")
execute("cd tool-mplabx-c-build && node buildLauncher.js sp=../ rp=./output genMK=true")
}
}
}
stage('GitHub-Deploy') {
when {
not {
changeRequest()
}
anyOf {
tag ''
}
}
steps {
script {
execute("git clone ${env.DEPLOY_TOOL_URL}")
withCredentials([usernamePassword(credentialsId: '8bit-examples.github.com', usernameVariable: 'USER_NAME', passwordVariable:'USER_PASS' )]) {
execute("cd ${env.DEPLOY_SCRIPT_DIR} && bash ${env.DEPLOY_SCRIPT_FILE} ${env.BITBUCKET_URL} ${env.GITHUB_URL} ${USER_NAME} ${USER_PASS} '--tag ${env.TAG_NAME}'")
}
sendSuccessfulGithubDeploymentEmail()
}
}
}
stage('Portal-Deploy') {
when {
not {
changeRequest()
}
tag ''
}
steps {
script {
def metadata = readJSON file:".main-meta/main.json"
def version = metadata.content.version
def project = metadata.content.projectName
if(version == env.TAG_NAME) {
def cmdArgs = "'{\"repoOwnerName\":\"$env.GITHUB_OWNER\",\"repoName\":\"$project\",\"tagName\":\"$version\"}'"
cmdArgs = cmdArgs.replaceAll("\"","\\\\\"")
execute("git clone https://bitbucket.microchip.com/scm/portal/bundles.git")
execute("cd bundles && chmod 755 ./portal-client-cli-linux")
execute("git clone https://bitbucket.microchip.com/scm/citd/tool-portal-client-launcher.git")
execute("cd tool-portal-client-launcher && node portalLauncher.js -app=../bundles/portal-client-cli-linux -cmd=\"uploadGitHub ${cmdArgs}\"")
sendSuccessfulPortalDeploymentEmail()
} else {
echo "Tag name is not equal to metadata content version."
execute("exit 1")
}
}
}
}
}
post {
failure {
script {
sendPipelineFailureEmail()
}
}
always {
archiveArtifacts artifacts: "tool-mplabx-c-build/output/**", allowEmptyArchive: true, fingerprint: true
}
}
}
def execute(String cmd) {
if(isUnix()) {
sh cmd
} else {
bat cmd
}
}
def sendPipelineFailureEmail () {
if (!"${env.CHANGE_AUTHOR_EMAIL}".equalsIgnoreCase("null")) {
mail to: "${env.CHANGE_AUTHOR_EMAIL}, ${params.NOTIFICATION_EMAIL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Pipeline failure. ${env.BUILD_URL}"
} else {
mail to: "${params.NOTIFICATION_EMAIL}",
subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
body: "Pipeline failure. ${env.BUILD_URL}"
}
}
def sendSuccessfulGithubDeploymentEmail () {
mail to: "${params.NOTIFICATION_EMAIL}",
subject: "Successful Github Deployment: ${currentBuild.fullDisplayName}",
body: "The changes have been successfully deployed to GitHub. ${env.GITHUB_URL}"
}
def sendSuccessfulPortalDeploymentEmail () {
mail to: "${params.NOTIFICATION_EMAIL}",
subject: "Successful Portal Deployment: ${currentBuild.fullDisplayName}",
body: "The changes have been successfully deployed to Discover Portal."
}