Advertisement
AtomicOs

Jenkinsfile

May 28th, 2021
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 KB | None | 0 0
  1. pipeline {
  2. agent none
  3. options {
  4. ansiColor('xterm')
  5. timestamps()
  6. }
  7. parameters {
  8. choice(name: 'CHANNEL', choices: ['nightly', 'dev', 'beta', 'release', 'development'])
  9. choice(name: 'BUILD_TYPE', choices: ['Release', 'Debug'])
  10. choice(name: 'BUILD_STATUS', choices: ['', 'SUCCESS', 'FAILURE', 'UNSTABLE', 'ABORTED'])
  11. booleanParam(name: 'TERMINATE_NODE', defaultValue: false)
  12. booleanParam(name: 'WIPE_WORKSPACE', defaultValue: false)
  13. booleanParam(name: 'SKIP_INIT', defaultValue: false)
  14. booleanParam(name: 'DISABLE_SCCACHE', defaultValue: false)
  15. booleanParam(name: 'SKIP_SIGNING', defaultValue: true)
  16. booleanParam(name: 'DCHECK_ALWAYS_ON', defaultValue: true)
  17. string(name: 'NODE_LABEL', defaultValue: '')
  18. string(name: 'SLACK_NOTIFY', defaultValue: '')
  19. }
  20. stages {
  21. stage('build') {
  22. agent { label 'master' }
  23. steps {
  24. script {
  25. REPO = JOB_NAME.substring(0, JOB_NAME.indexOf('-build-pr'))
  26. OTHER_REPO = REPO.equals('brave-browser') ? 'brave-core' : 'brave-browser'
  27. PLATFORM = JOB_NAME.substring(JOB_NAME.indexOf('-build-pr') + 10, JOB_NAME.indexOf('/PR-'))
  28. PIPELINE_NAME = 'pr-brave-browser-' + CHANGE_BRANCH.replace('/', '-') + '-' + PLATFORM
  29.  
  30. if (params.BUILD_STATUS) {
  31. if (Jenkins.instance.getItemByFullName(JOB_NAME).getLastBuild().getCause(hudson.model.Cause$UpstreamCause) == null) {
  32. echo 'Aborting build as it has been started manually with BUILD_STATUS set'
  33. currentBuild.result = 'ABORTED'
  34. return
  35. }
  36. else {
  37. echo "Setting other PR build status to ${params.BUILD_STATUS}"
  38. currentBuild.result = params.BUILD_STATUS
  39. return
  40. }
  41. }
  42.  
  43. withCredentials([usernamePassword(credentialsId: 'brave-builds-github-token-for-pr-builder', usernameVariable: 'PR_BUILDER_USER', passwordVariable: 'PR_BUILDER_TOKEN')]) {
  44. GITHUB_API = 'https://api.github.com/repos/brave'
  45. GITHUB_AUTH_HEADERS = [[name: 'Authorization', value: 'token ' + PR_BUILDER_TOKEN]]
  46. def prDetails = readJSON(text: httpRequest(url: GITHUB_API + '/' + REPO + '/pulls?head=brave:' + CHANGE_BRANCH, customHeaders: GITHUB_AUTH_HEADERS, quiet: true).content)[0]
  47. SKIP = prDetails.draft.equals(true) || prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip') }.equals(1) || prDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-${PLATFORM}") }.equals(1)
  48. RUN_NETWORK_AUDIT = prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/run-network-audit') }.equals(1)
  49. def branchExistsInOtherRepo = httpRequest(url: GITHUB_API + '/' + OTHER_REPO + '/branches/' + CHANGE_BRANCH, validResponseCodes: '100:499', customHeaders: GITHUB_AUTH_HEADERS, quiet: true).status.equals(200)
  50. if (branchExistsInOtherRepo) {
  51. def otherPrDetails = readJSON(text: httpRequest(url: GITHUB_API + '/' + OTHER_REPO + '/pulls?head=brave:' + CHANGE_BRANCH, customHeaders: GITHUB_AUTH_HEADERS, quiet: true).content)[0]
  52. if (otherPrDetails) {
  53. env.OTHER_PR_NUMBER = otherPrDetails.number
  54. SKIP = SKIP || otherPrDetails.draft.equals(true) || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip') }.equals(1) || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-${PLATFORM}") }.equals(1)
  55. RUN_NETWORK_AUDIT = RUN_NETWORK_AUDIT || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/run-network-audit') }.equals(1)
  56. }
  57. }
  58. }
  59.  
  60. if (SKIP && PLATFORM != 'pre-init' && PLATFORM != 'post-init' ) {
  61. echo "Aborting build as PRs are either in draft or have a skip label (CI/skip or CI/skip-${PLATFORM})"
  62. currentBuild.result = 'SUCCESS'
  63. return
  64. }
  65.  
  66. for (build in Jenkins.instance.getItemByFullName(JOB_NAME).builds) {
  67. if (build.isBuilding() && build.getNumber() < BUILD_NUMBER.toInteger()) {
  68. echo 'Aborting older running build ' + build
  69. build.doStop()
  70. }
  71. }
  72.  
  73. jobDsl(scriptText: """
  74. pipelineJob('${PIPELINE_NAME}') {
  75. // this list has to match the parameters in the Jenkinsfile from devops repo
  76. parameters {
  77. choiceParam('CHANNEL', ['nightly', 'dev', 'beta', 'release', 'development'])
  78. choiceParam('BUILD_TYPE', ['Release', 'Debug'])
  79. booleanParam('TERMINATE_NODE', false)
  80. booleanParam('WIPE_WORKSPACE', false)
  81. booleanParam('SKIP_INIT', false)
  82. booleanParam('DISABLE_SCCACHE', false)
  83. booleanParam('SKIP_SIGNING', true)
  84. booleanParam('DCHECK_ALWAYS_ON', true)
  85. booleanParam('RUN_NETWORK_AUDIT', false)
  86. stringParam('BRANCH', '${CHANGE_BRANCH}')
  87. stringParam('NODE_LABEL', '')
  88. stringParam('SLACK_NOTIFY', '')
  89. }
  90. definition {
  91. cpsScm {
  92. scm {
  93. git {
  94. remote {
  95. credentials('brave-builds-github-token-for-pr-builder')
  96. github('brave/devops', 'https')
  97. }
  98. branch('master')
  99. }
  100. }
  101. scriptPath("jenkins/jobs/browser/pr-brave-browser-${PLATFORM}.Jenkinsfile")
  102. }
  103. }
  104. }
  105. """)
  106.  
  107. params = [
  108. string(name: 'CHANNEL', value: params.CHANNEL),
  109. string(name: 'BUILD_TYPE', value: params.BUILD_TYPE),
  110. booleanParam(name: "TERMINATE_NODE", value: params.TERMINATE_NODE),
  111. booleanParam(name: 'WIPE_WORKSPACE', value: params.WIPE_WORKSPACE),
  112. booleanParam(name: 'SKIP_INIT', value: params.SKIP_INIT),
  113. booleanParam(name: 'DISABLE_SCCACHE', value: params.DISABLE_SCCACHE),
  114. booleanParam(name: 'SKIP_SIGNING', value: params.SKIP_SIGNING),
  115. booleanParam(name: 'DCHECK_ALWAYS_ON', value: params.DCHECK_ALWAYS_ON),
  116. booleanParam(name: 'RUN_NETWORK_AUDIT', value: RUN_NETWORK_AUDIT),
  117. string(name: 'BRANCH', value: CHANGE_BRANCH),
  118. string(name: 'NODE_LABEL', value: params.NODE_LABEL),
  119. string(name: 'SLACK_NOTIFY', value: params.SLACK_NOTIFY)
  120. ]
  121.  
  122. currentBuild.result = build(job: PIPELINE_NAME, parameters: params, propagate: false).result
  123. if (env.OTHER_PR_NUMBER) {
  124. build(job: OTHER_REPO + '-build-pr-' + PLATFORM + '/PR-' + env.OTHER_PR_NUMBER, parameters: [string(name: 'BUILD_STATUS', value: currentBuild.result)], propagate: false)
  125. }
  126. }
  127. }
  128. }
  129. }
  130. post {
  131. always {
  132. node('master') {
  133. script {
  134. sh 'rm -rf .git/index.lock'
  135. }
  136. }
  137. }
  138. }
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement