Skip to content

Commit e8f240a

Browse files
committed
Addressed review comments
1 parent 6f8d786 commit e8f240a

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

.citd/Jenkinsfilek8s

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ pipeline {
1515
BITBUCKET_CREDENTIAL_ID = 'BITBUCKET_INTERNAL_TOKEN'
1616
GITHUB_PRODUCTION_DEPLOY_URL ='https://github.com/microchip-pic-avr-examples'
1717
GITHUB_TEST_DEPLOY_URL ='https://github.com/mchpTestArea'
18-
//Selects the deployment URL(production or test) based on the merge target branch, selects "microchip-pic-avr-examples" if target branch is "master" , if target branch is "test_deploy" selects "mchpTestArea"
19-
GITHUB_URL = ("${env.BRANCH_NAME}" == "master") ? GITHUB_PRODUCTION_DEPLOY_URL : ("${env.BRANCH_NAME}" == "test_deploy") ? GITHUB_TEST_DEPLY_URL : null
18+
//Selects the deployment URL(production or test) based on the merge target branch, selects "microchip-pic-avr-examples" if target branch is "master" , if target branch is "test_deploy" selects "mchpTestArea" else null
19+
GITHUB_URL = getGitHubUrl("${GITHUB_PRODUCTION_DEPLOY_URL}","${GITHUB_TEST_DEPLOY_URL}")
2020
GITHUB_PRODUCTION_DEPLOY_CREDENTIAL_ID='GITHUB_MICROCHIP_PIC_AVR_EXAMPLES_TOKEN'
2121
GITHUB_TEST_DEPLOY_CREDENTIAL_ID='GITHUB_PIC_AVR_TEST_TOKEN'
22-
GITHUB_CREDENTIAL_ID = ("${env.BRANCH_NAME}" == "master") ? GITHUB_PRODUCTION_DEPLOY_CREDENTIAL_ID : ("${env.BRANCH_NAME}" == "test_deploy") ? GITHUB_TEST_DEPLOY_CREDENTIAL_ID : null
22+
PRODUCTION_DEPLOY_ORG = 'microchip-pic-avr-examples'
23+
TEST_DEPLOY_ORG = 'mchpTestArea'
24+
//Gets the Github credential id based on the deployment organization
25+
GITHUB_CREDENTIAL_ID = getGitHubCredentialId("${GITHUB_URL}","${PRODUCTION_DEPLOY_ORG}","${TEST_DEPLOY_ORG}","${GITHUB_PRODUCTION_DEPLOY_CREDENTIAL_ID}","${GITHUB_TEST_DEPLOY_CREDENTIAL_ID}")
2326
//Files or folders to be excluded from deployment, if multiple files or folders use comma separator
2427
DEPLOY_EXCLUDE_FOLDER_FILE_LIST = 'mchp_private'
2528
//Branch(s) to be deployed, if multiple branches use comma separator. ${env.BRANCH_NAME} is the target branch of the PR.
@@ -45,8 +48,6 @@ pipeline {
4548
stage('Build') {
4649
steps {
4750
script {
48-
echo "${env.GITHUB_URL}"
49-
echo "${env.GITHUB_CREDENTIAL_ID}"
5051
execute("git clone https://bitbucket.microchip.com/scm/citd/tool-mplabx-c-build.git")
5152
execute("cd ./tool-mplabx-c-build && node buildLauncher.js sp=../ rp=./output genMK=true")
5253
}
@@ -110,7 +111,7 @@ pipeline {
110111
def asString = topics.join(", ")
111112
asString = asString.replace("\n", "").replace(" ", "").replace("\t", "").replace("\r", "")
112113
Boolean visibility = true
113-
if(env.GITHUB_URL.contains('microchip-pic-avr-examples'))
114+
if(env.GITHUB_URL.contains(env.PRODUCTION_DEPLOY_ORG))
114115
{
115116
visibility = false
116117
}
@@ -242,3 +243,24 @@ String readJsonObject() {
242243
def jsonObj = readJSON interpolate: true, file: "${env.SOURCE_PROJECT_META_DATA}"
243244
return jsonObj
244245
}
246+
247+
def getGitHubUrl(String productionUrl, String testDeployUrl) {
248+
String branchName = "${env.BRANCH_NAME}";
249+
if(branchName == 'master') {
250+
return productionUrl;
251+
} else if(branchName == 'test_deploy') {
252+
return testDeployUrl;
253+
} else {
254+
return null
255+
}
256+
}
257+
258+
def getGitHubCredentialId(String deployUrl, String productionDeployOrg, String testDeployOrg, String githubProductionDeployCredential, String githubTestDeployCredential) {
259+
if(deployUrl.contains(productionDeployOrg)) {
260+
return githubProductionDeployCredential;
261+
} else if(deployUrl.contains(testDeployOrg)) {
262+
return githubTestDeployCredential;
263+
} else {
264+
return null
265+
}
266+
}

0 commit comments

Comments
 (0)