-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathJenkinsfilek8s
158 lines (139 loc) · 6.58 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
// Jenkinsfile v2.0.1
pipeline {
agent {
kubernetes {
defaultContainer 'arduino-gcc'
yamlFile 'cloudprovider.yaml'
}
}
options {
timestamps()
timeout(time: 30, unit: 'MINUTES')
}
environment {
DEPLOY_TOOL_URL = 'https://bitbucket.microchip.com/scm/citd/tool-github-deploy.git'
DEPLOY_SCRIPT_FILE = 'tool-github-deploy/tool-github-deploy/tool-github-deploy.py'
BITBUCKET_REPO = 'https://bitbucket.microchip.com/scm/mcu8mass/avr-iot-cellular-arduino-library.git'
GITHUB_REPO = 'https://github.com/microchip-pic-avr-solutions/avr-iot-cellular-arduino-library'
GITHUB_REPO_SHORT = 'avr-iot-cellular-arduino-library'
GITHUB_ORG = 'microchip-pic-avr-solutions'
TARGET_BRANCH = 'main'
}
stages {
stage('setup') {
steps {
checkout scm
script {
env.GIT_TAG = gitTag()
env.GIT_COMMIT = getCommit()
if(env.GIT_TAG != '') {
currentBuild.displayName = "#${BUILD_NUMBER} | ${JOB_NAME} | RELEASE-CANDIDATE-${env.GIT_TAG}"
env.RELEASE_NAME = env.GIT_TAG
} else {
currentBuild.displayName = "#${BUILD_NUMBER} | ${JOB_NAME} | ${env.GIT_COMMIT}"
env.RELEASE_NAME = env.GIT_COMMIT
}
}
}
}
stage('install-libraries') {
steps {
sh 'wget http://drazzy.com/package_drazzy.com_index.json --no-check-certificate'
sh 'arduino-cli core update-index --additional-urls "file://$PWD/package_drazzy.com_index.json"'
sh 'arduino-cli core install --additional-urls "file://$PWD/package_drazzy.com_index.json" DxCore:megaavr'
sh 'arduino-cli lib update-index'
sh 'arduino-cli lib install ArduinoJson'
sh 'arduino-cli lib install "Adafruit GPS Library"'
sh 'arduino-cli lib install "Adafruit AHTX0"'
sh 'arduino-cli lib install "Adafruit seesaw Library"'
sh 'arduino-cli lib install "Adafruit VEML7700 Library"'
sh 'ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://bitbucket.microchip.com/scm/mcu8mass/veml3328_arduino_driver.git'
sh 'ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL=true arduino-cli lib install --git-url https://bitbucket.microchip.com/scm/mcu8mass/mcp9808_arduino_driver.git'
}
}
stage('linter') {
steps {
sh 'arduino-lint --library-manager update --compliance permissive --project-type library'
script {
env.DEP_ERROR = getDependencyError()
if (env.DEP_ERROR != '') {
error("LP048 error: depends field item(s) not found")
}
}
}
}
stage('build-examples') {
steps {
sh 'chmod +x ./scripts/compile_examples.sh'
sh './scripts/compile_examples.sh'
}
}
stage('bundle') {
steps {
sh 'chmod +x ./scripts/bundle.sh'
sh './scripts/bundle.sh $RELEASE_NAME'
}
}
stage('deploy'){
// Only run if git tag exists and it's the master branch
when {
allOf {
branch env.TARGET_BRANCH
}
}
// Multi-Stage Deploy
stages {
// Clone the deploy tool
stage('GitHub-Setup') {
steps {
sh "git clone --branch 1.6.0 ${env.DEPLOY_TOOL_URL}"
sh "pip3 install PyGithub atlassian-python-api jsonschema packaging lxml"
}
}
// Sync the bitbucket repository with the github repository
stage('GitHub-Sync') {
steps {
script {
withCredentials([usernamePassword(credentialsId: 'pic_avr_github', usernameVariable: 'USER_NAME', passwordVariable:'PASS' )]) {
sh "python3 ${env.DEPLOY_SCRIPT_FILE} -deploy=true -gpat=${PASS} -dgid=${USER_NAME} -dburl=${env.BITBUCKET_REPO} -dgurl=${env.GITHUB_REPO} -dbranch=${env.TARGET_BRANCH} -dm=True"
}
}
}
}
// Create a new release
stage('GitHub-Release') {
when {
expression {
env.GIT_TAG != ''
}
}
steps {
script {
withCredentials([usernamePassword(credentialsId: 'pic_avr_github', usernameVariable: 'USER_NAME', passwordVariable:'PASS' )]) {
sh "python3 ${env.DEPLOY_SCRIPT_FILE} -rlo=true -gpat=${PASS} -dgid=${USER_NAME} -rpn=${GITHUB_REPO_SHORT} -rporg=${GITHUB_ORG} -rltt=\"${env.GIT_TAG}\" -rltv=\"${env.GIT_TAG}\" -rlua=\"avr-iot-cellular-${env.GIT_TAG}.zip,sandbox.hex\""
}
}
}
}
}
}
}
post {
success {
archiveArtifacts artifacts: '**/avr-iot-cellular-*.zip, **/sandbox.hex'
}
}
}
String getCommit() {
return sh(script: 'git rev-parse HEAD', returnStdout: true)?.trim()
}
String gitTag(){
return sh(script: "git tag --contains", returnStdout: true)?.trim()
}
def initializeGitForDeployment() {
execute("git config --global user.email 'microchip@microchip.com'")
execute("git config --global user.name 'Microchip Technology'")
}
String getDependencyError() {
return sh(script: "! arduino-lint --library-manager update --compliance strict --format json | grep LP048", returnStdout: true)?.trim()
}