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