1+ pipeline {
2+ agent {
3+ kubernetes {
4+ label 'atmega4809-adc-basics-mplab'
5+ defaultContainer 'xc8-mplabx'
6+ yamlFile 'cloudprovider.yml'
7+ }
8+ }
9+
10+ parameters {
11+ string( name: 'NOTIFICATION_EMAIL',
12+ defaultValue: 'PICAVR_Examples_GateKeepers@microchip.com',
13+ description: "Email to send build failure and fixed notifications.")
14+ }
15+
16+ environment {
17+ GITHUB_URL ='https://github.com/microchip-pic-avr-examples/atmega4809-adc-basics-mplab.git'
18+ BITBUCKET_URL = 'https://bitbucket.microchip.com/scm/ebe/atmega4809-adc-basics-mplab.git'
19+ DEPLOY_TOOL_URL = 'https://bitbucket.microchip.com/scm/citd/tool-github-deploy.git'
20+ DEPLOY_SCRIPT_DIR = 'tool-github-deploy'
21+ DEPLOY_SCRIPT_FILE = 'deploy-source-as-is.sh'
22+ }
23+
24+ options {
25+ timestamps()
26+ timeout(time: 20, unit: 'MINUTES')
27+ }
28+
29+ stages {
30+ stage('Checkout') {
31+ steps {
32+ checkout scm
33+ }
34+ }
35+
36+ stage('Pre-build') {
37+ steps {
38+ script {
39+ MPLABX_PATH= sh (script: 'update-alternatives --list MPLABX_PATH',returnStdout: true).trim()
40+ COMPILER_PATH= sh (script: 'update-alternatives --list XC8_PATH',returnStdout: true).trim()
41+ def pDir = "${MPLABX_PATH}/packs"
42+ def ver = COMPILER_PATH.split('/')[4].substring(1)
43+
44+ execute("git clone https://bitbucket.microchip.com/scm/citd/tool-mplabx-c-project-generator.git")
45+ execute("cd tool-mplabx-c-project-generator && node configGenerator.js sp=../ v8=${ver} packs=${pDir}")
46+ }
47+ }
48+ }
49+
50+ stage('Build') {
51+ steps {
52+ script {
53+ execute("git clone https://bitbucket.microchip.com/scm/citd/tool-mplabx-c-build.git")
54+ execute("cd tool-mplabx-c-build && node buildLauncher.js sp=../ rp=./output genMK=true")
55+ }
56+ }
57+ }
58+
59+ stage('Deploy') {
60+ when {
61+ not {
62+ changeRequest()
63+ }
64+ anyOf {
65+ tag ''
66+ }
67+ }
68+ steps {
69+ script {
70+ execute("git clone ${env.DEPLOY_TOOL_URL}")
71+
72+ withCredentials([usernamePassword(credentialsId: '8bit-examples.github.com', usernameVariable: 'USER_NAME', passwordVariable:'USER_PASS' )]) {
73+ 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}'")
74+ }
75+
76+ sendSuccessfulGithubDeploymentEmail()
77+ }
78+ }
79+ }
80+ }
81+
82+ post {
83+ failure {
84+ script {
85+ sendPipelineFailureEmail()
86+ }
87+ }
88+ always {
89+ archiveArtifacts artifacts: "tool-mplabx-c-build/output/**", allowEmptyArchive: true, fingerprint: true
90+ }
91+ }
92+ }
93+
94+ def execute(String cmd) {
95+ if(isUnix()) {
96+ sh cmd
97+ } else {
98+ bat cmd
99+ }
100+ }
101+
102+ def sendPipelineFailureEmail () {
103+ if (!"${env.CHANGE_AUTHOR_EMAIL}".equalsIgnoreCase("null")) {
104+ mail to: "${env.CHANGE_AUTHOR_EMAIL}, ${params.NOTIFICATION_EMAIL}",
105+ subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
106+ body: "Pipeline failure. ${env.BUILD_URL}"
107+ } else {
108+ mail to: "${params.NOTIFICATION_EMAIL}",
109+ subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
110+ body: "Pipeline failure. ${env.BUILD_URL}"
111+ }
112+ }
113+
114+ def sendSuccessfulGithubDeploymentEmail () {
115+ mail to: "${params.NOTIFICATION_EMAIL}",
116+ subject: "Successful Deployment: ${currentBuild.fullDisplayName}",
117+ body: "The changes have been successfully deployed to GitHub. ${env.GITHUB_URL}"
118+ }
0 commit comments