1
+ // Jenkinsfilek8s v1.2.0
2
+
3
+ pipeline {
4
+ agent {
5
+ kubernetes {
6
+ label 'avr128db48-getting-started-with-opamp-mplab-mcc'
7
+ defaultContainer 'xc8-mplabx'
8
+ yamlFile 'cloudprovider.yml'
9
+ }
10
+ }
11
+
12
+ parameters {
13
+ string( name: 'NOTIFICATION_EMAIL',
14
+ defaultValue: 'PICAVR_Examples_GateKeepers@microchip.com',
15
+ description: "Email to send build failure and fixed notifications.")
16
+ }
17
+
18
+ environment {
19
+ GITHUB_OWNER = 'microchip-pic-avr-examples'
20
+ GITHUB_URL ='https://github.com/microchip-pic-avr-examples/avr128db48-getting-started-with-opamp-mplab-mcc.git'
21
+ BITBUCKET_URL = 'https://bitbucket.microchip.com/scm/ebe/avr128db48-getting-started-with-opamp-mplab-mcc.git'
22
+ DEPLOY_TOOL_URL = 'https://bitbucket.microchip.com/scm/citd/tool-github-deploy.git'
23
+ DEPLOY_SCRIPT_DIR = 'tool-github-deploy'
24
+ DEPLOY_SCRIPT_FILE = 'deploy-source-as-is.sh'
25
+ }
26
+
27
+ options {
28
+ timestamps()
29
+ timeout(time: 30, unit: 'MINUTES')
30
+ }
31
+
32
+ stages {
33
+ stage('Checkout') {
34
+ steps {
35
+ checkout scm
36
+ }
37
+ }
38
+
39
+ stage('metadata') {
40
+ steps {
41
+ script {
42
+ execute("pip install jsonschema")
43
+ execute("git clone https://bitbucket.microchip.com/scm/citd/metadata-schema.git")
44
+ execute("git clone https://bitbucket.microchip.com/scm/citd/tool-metadata-validator.git")
45
+ execute("cd tool-metadata-validator && python metadata-validator.py -data '../.main-meta/main.json' -schema '../metadata-schema/main-schema.json'")
46
+ }
47
+ }
48
+ }
49
+
50
+ stage('Pre-build') {
51
+ steps {
52
+ script {
53
+ MPLABX_PATH= sh (script: 'update-alternatives --list MPLABX_PATH',returnStdout: true).trim()
54
+ COMPILER_PATH= sh (script: 'update-alternatives --list XC8_PATH',returnStdout: true).trim()
55
+ def pDir = "${MPLABX_PATH}/packs"
56
+ def ver = COMPILER_PATH.split('/')[4].substring(1)
57
+
58
+ execute("git clone https://bitbucket.microchip.com/scm/citd/tool-mplabx-c-project-generator.git")
59
+ execute("cd tool-mplabx-c-project-generator && node configGenerator.js sp=../ v8=${ver} packs=${pDir}")
60
+ }
61
+ }
62
+ }
63
+
64
+ stage('Build') {
65
+ steps {
66
+ script {
67
+ execute("git clone https://bitbucket.microchip.com/scm/citd/tool-mplabx-c-build.git")
68
+ execute("cd tool-mplabx-c-build && node buildLauncher.js sp=../ rp=./output genMK=true")
69
+ }
70
+ }
71
+ }
72
+
73
+ stage('GitHub-Deploy') {
74
+ when {
75
+ not {
76
+ changeRequest()
77
+ }
78
+ anyOf {
79
+ tag ''
80
+ }
81
+ }
82
+ steps {
83
+ script {
84
+ execute("git clone ${env.DEPLOY_TOOL_URL}")
85
+
86
+ withCredentials([usernamePassword(credentialsId: '8bit-examples.github.com', usernameVariable: 'USER_NAME', passwordVariable:'USER_PASS' )]) {
87
+ 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}'")
88
+ }
89
+
90
+ sendSuccessfulGithubDeploymentEmail()
91
+ }
92
+ }
93
+ }
94
+
95
+ stage('Portal-Deploy') {
96
+ when {
97
+ not {
98
+ changeRequest()
99
+ }
100
+ tag ''
101
+ }
102
+ steps {
103
+ script {
104
+ def metadata = readJSON file:".main-meta/main.json"
105
+ def version = metadata.content.version
106
+ def project = metadata.content.projectName
107
+
108
+ if(version == env.TAG_NAME) {
109
+ def cmdArgs = "'{\"repoOwnerName\":\"$env.GITHUB_OWNER\",\"repoName\":\"$project\",\"tagName\":\"$version\"}'"
110
+ cmdArgs = cmdArgs.replaceAll("\"","\\\\\"")
111
+
112
+ execute("git clone https://bitbucket.microchip.com/scm/portal/bundles.git")
113
+ execute("cd bundles && chmod 755 ./portal-client-cli-linux")
114
+ execute("git clone https://bitbucket.microchip.com/scm/citd/tool-portal-client-launcher.git")
115
+ execute("cd tool-portal-client-launcher && node portalLauncher.js -app=../bundles/portal-client-cli-linux -cmd=\"uploadGitHub ${cmdArgs}\"")
116
+ sendSuccessfulPortalDeploymentEmail()
117
+ } else {
118
+ echo "Tag name is not equal to metadata content version."
119
+ execute("exit 1")
120
+ }
121
+
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+
128
+ post {
129
+ failure {
130
+ script {
131
+ sendPipelineFailureEmail()
132
+ }
133
+ }
134
+ always {
135
+ archiveArtifacts artifacts: "tool-mplabx-c-build/output/**", allowEmptyArchive: true, fingerprint: true
136
+ }
137
+ }
138
+ }
139
+
140
+ def execute(String cmd) {
141
+ if(isUnix()) {
142
+ sh cmd
143
+ } else {
144
+ bat cmd
145
+ }
146
+ }
147
+
148
+ def sendPipelineFailureEmail () {
149
+ if (!"${env.CHANGE_AUTHOR_EMAIL}".equalsIgnoreCase("null")) {
150
+ mail to: "${env.CHANGE_AUTHOR_EMAIL}, ${params.NOTIFICATION_EMAIL}",
151
+ subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
152
+ body: "Pipeline failure. ${env.BUILD_URL}"
153
+ } else {
154
+ mail to: "${params.NOTIFICATION_EMAIL}",
155
+ subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
156
+ body: "Pipeline failure. ${env.BUILD_URL}"
157
+ }
158
+ }
159
+
160
+ def sendSuccessfulGithubDeploymentEmail () {
161
+ mail to: "${params.NOTIFICATION_EMAIL}",
162
+ subject: "Successful Github Deployment: ${currentBuild.fullDisplayName}",
163
+ body: "The changes have been successfully deployed to GitHub. ${env.GITHUB_URL}"
164
+ }
165
+
166
+ def sendSuccessfulPortalDeploymentEmail () {
167
+ mail to: "${params.NOTIFICATION_EMAIL}",
168
+ subject: "Successful Portal Deployment: ${currentBuild.fullDisplayName}",
169
+ body: "The changes have been successfully deployed to Discover Portal."
170
+ }
0 commit comments