Skip to content

Commit

Permalink
Merge pull request #5673 from brave/mplesa-ci-pipeline-sync-1.9.x
Browse files Browse the repository at this point in the history
ci pipeline sync 1.9.x
  • Loading branch information
mihaiplesa authored May 27, 2020
2 parents 97f675b + efa1e25 commit ad11ce6
Showing 1 changed file with 92 additions and 121 deletions.
213 changes: 92 additions & 121 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,53 +1,90 @@
pipeline {
agent none
options {
ansiColor("xterm")
timeout(time: 6, unit: "HOURS")
ansiColor('xterm')
timeout(time: 6, unit: 'HOURS')
timestamps()
}
parameters {
choice(name: "CHANNEL", choices: ["nightly", "dev", "beta", "release", "development"])
choice(name: "BUILD_TYPE", choices: ["Release", "Debug"])
booleanParam(name: "WIPE_WORKSPACE", defaultValue: false)
booleanParam(name: "SKIP_INIT", defaultValue: false)
booleanParam(name: "DISABLE_SCCACHE", defaultValue: false)
booleanParam(name: "SKIP_SIGNING", defaultValue: true)
booleanParam(name: "DCHECK_ALWAYS_ON", defaultValue: true)
}
environment {
GITHUB_CREDENTIAL_ID = "brave-builds-github-token-for-pr-builder"
SLACK_USERNAME_MAP = credentials("github-to-slack-username-map")
choice(name: 'CHANNEL', choices: ['nightly', 'dev', 'beta', 'release', 'development'])
choice(name: 'BUILD_TYPE', choices: ['Release', 'Debug'])
choice(name: 'BUILD_STATUS', choices: ['', 'SUCCESS', 'FAILURE', 'UNSTABLE', 'ABORTED'])
booleanParam(name: 'WIPE_WORKSPACE', defaultValue: false)
booleanParam(name: 'SKIP_INIT', defaultValue: false)
booleanParam(name: 'DISABLE_SCCACHE', defaultValue: false)
booleanParam(name: 'SKIP_SIGNING', defaultValue: true)
booleanParam(name: 'DCHECK_ALWAYS_ON', defaultValue: true)
}
stages {
stage("env") {
stage('env') {
steps {
withCredentials([usernamePassword(credentialsId: "${GITHUB_CREDENTIAL_ID}", usernameVariable: "PR_BUILDER_USER", passwordVariable: "PR_BUILDER_TOKEN")]) {
withCredentials([usernamePassword(credentialsId: 'brave-builds-github-token-for-pr-builder', usernameVariable: 'PR_BUILDER_USER', passwordVariable: 'PR_BUILDER_TOKEN')]) {
setEnv()
}
}
}
stage("abort") {
stage('abort') {
steps {
checkAndAbortBuild()
}
}
stage("build-all") {
agent { label "master" }
stage('build') {
agent { label 'master' }
when {
beforeAgent true
expression { !SKIP }
}
steps {
startBraveBrowserBuild()
script {
if (params.BUILD_STATUS) {
if (isStartedManually()) {
echo 'Aborting build as it has been started manually with BUILD_STATUS set'
stopCurrentBuild()
}
else {
currentBuild.result = params.BUILD_STATUS
}
}
else {
startBraveBrowserBuild()
}
}
}
}
}
}

def setEnv() {
GITHUB_API = 'https://api.github.com/repos/brave'
REPO = JOB_NAME.substring(0, JOB_NAME.indexOf('-build-pr'))
OTHER_REPO = REPO.equals('brave-browser') ? 'brave-core' : 'brave-browser'
def prDetails = readJSON(text: httpRequest(url: GITHUB_API + '/' + REPO + '/pulls?head=brave:' + CHANGE_BRANCH, customHeaders: [[name: 'Authorization', value: 'token ' + PR_BUILDER_TOKEN]]).content)[0]
SKIP = prDetails.draft.equals(true) || prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip') }.equals(1)
SKIP_ANDROID = prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-android') }.equals(1)
SKIP_IOS = prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-ios') }.equals(1)
SKIP_LINUX = prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-linux') }.equals(1)
SKIP_MACOS = prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-macos') }.equals(1)
SKIP_WINDOWS = prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-windows') }.equals(1)
RUN_NETWORK_AUDIT = prDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/run-network-audit') }.equals(1)
def branchExistsInOtherRepo = httpRequest(url: GITHUB_API + '/' + OTHER_REPO + '/branches/' + CHANGE_BRANCH, validResponseCodes: '100:499', customHeaders: [[name: 'Authorization', value: 'token ' + PR_BUILDER_TOKEN]]).status.equals(200)
if (branchExistsInOtherRepo) {
def otherPrDetails = readJSON(text: httpRequest(url: GITHUB_API + '/' + OTHER_REPO + '/pulls?head=brave:' + CHANGE_BRANCH, customHeaders: [[name: 'Authorization', value: 'token ' + PR_BUILDER_TOKEN]]).content)[0]
if (otherPrDetails) {
env.OTHER_PR_NUMBER = otherPrDetails.number
SKIP = SKIP || otherPrDetails.draft.equals(true) || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip') }.equals(1)
SKIP_ANDROID = SKIP_ANDROID || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-android') }.equals(1)
SKIP_IOS = SKIP_IOS || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-ios') }.equals(1)
SKIP_LINUX = SKIP_LINUX || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-linux') }.equals(1)
SKIP_MACOS = SKIP_MACOS || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-macos') }.equals(1)
SKIP_WINDOWS = SKIP_WINDOWS || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/skip-windows') }.equals(1)
RUN_NETWORK_AUDIT = RUN_NETWORK_AUDIT || otherPrDetails.labels.count { label -> label.name.equalsIgnoreCase('CI/run-network-audit') }.equals(1)
}
}
}

@NonCPS
def stopCurrentBuild() {
Jenkins.instance.getItemByFullName(JOB_NAME).getLastBuild().doStop()
sleep(time: 1, unit: "MINUTES")
}

@NonCPS
Expand All @@ -60,102 +97,41 @@ def getBuilds() {
return Jenkins.instance.getItemByFullName(JOB_NAME).builds
}

def setEnv() {
CHANNEL = params.CHANNEL
BUILD_TYPE = params.BUILD_TYPE
WIPE_WORKSPACE = params.WIPE_WORKSPACE
SKIP_INIT = params.SKIP_INIT
DISABLE_SCCACHE = params.DISABLE_SCCACHE
SKIP_SIGNING = params.SKIP_SIGNING
DCHECK_ALWAYS_ON = params.DCHECK_ALWAYS_ON
RUN_NETWORK_AUDIT = false
SKIP = false
SKIP_ANDROID = false
SKIP_IOS = false
SKIP_LINUX = false
SKIP_MACOS = false
SKIP_WINDOWS = false
BASE_BRANCH = "master"
BRAVE_BROWSER_BRANCH = "master"
BRAVE_CORE_BRANCH = BRANCH_NAME
GITHUB_API = "https://api.github.com/repos/brave"
if (CHANGE_BRANCH) {
BASE_BRANCH = CHANGE_TARGET
BRAVE_BROWSER_BRANCH = CHANGE_TARGET
BRAVE_CORE_BRANCH = CHANGE_BRANCH
def braveCorePrDetails = readJSON(text: httpRequest(url: GITHUB_API + "/brave-core/pulls?head=brave:" + BRAVE_CORE_BRANCH, customHeaders: [[name: "Authorization", value: "token ${PR_BUILDER_TOKEN}"]]).content)[0]
SKIP = braveCorePrDetails.mergeable_state.equals("draft") || braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip") }.equals(1)
SKIP_ANDROID = braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-android") }.equals(1)
SKIP_IOS = braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-ios") }.equals(1)
SKIP_LINUX = braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-linux") }.equals(1)
SKIP_MACOS = braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-macos") }.equals(1)
SKIP_WINDOWS = braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-windows") }.equals(1)
RUN_NETWORK_AUDIT = braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/run-network-audit") }.equals(1)
SLACK_USERNAME = readJSON(text: SLACK_USERNAME_MAP)[braveCorePrDetails.user.login]
BRANCH_PRODUCTIVITY_HOMEPAGE = "https://github.com/brave/brave-core/pull/${braveCorePrDetails.number}"
BRANCH_PRODUCTIVITY_NAME = "Brave Core PR #${braveCorePrDetails.number}"
BRANCH_PRODUCTIVITY_DESCRIPTION = braveCorePrDetails.title
BRANCH_PRODUCTIVITY_USER = braveCorePrDetails.user.login
def branchExistsInBraveBrowser = httpRequest(url: GITHUB_API + "/brave-browser/branches/" + BRAVE_CORE_BRANCH, validResponseCodes: "100:499", customHeaders: [[name: "Authorization", value: "token ${PR_BUILDER_TOKEN}"]]).status.equals(200)
if (branchExistsInBraveBrowser) {
BRAVE_BROWSER_BRANCH = BRAVE_CORE_BRANCH
def braveBrowserPrDetails = readJSON(text: httpRequest(url: GITHUB_API + "/brave-browser/pulls?head=brave:" + BRAVE_BROWSER_BRANCH, customHeaders: [[name: "Authorization", value: "token ${PR_BUILDER_TOKEN}"]]).content)[0]
if (braveBrowserPrDetails) {
SKIP = SKIP || braveBrowserPrDetails.mergeable_state.equals("draft") || braveCorePrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip") }.equals(1)
SKIP_ANDROID = SKIP_ANDROID || braveBrowserPrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-android") }.equals(1)
SKIP_IOS = SKIP_IOS || braveBrowserPrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-ios") }.equals(1)
SKIP_LINUX = SKIP_LINUX || braveBrowserPrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-linux") }.equals(1)
SKIP_MACOS = SKIP_MACOS || braveBrowserPrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-macos") }.equals(1)
SKIP_WINDOWS = SKIP_WINDOWS || braveBrowserPrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/skip-windows") }.equals(1)
RUN_NETWORK_AUDIT = RUN_NETWORK_AUDIT || braveBrowserPrDetails.labels.count { label -> label.name.equalsIgnoreCase("CI/run-network-audit") }.equals(1)
}
}
}
}

def checkAndAbortBuild() {
if (SKIP) {
echo "Aborting build as PR is in draft or has \"CI/skip\" label"
echo 'Aborting build as PR is in draft or has "CI/skip" label'
stopCurrentBuild()
}
else {
for (build in getBuilds()) {
if (build.isBuilding() && build.getNumber() < BUILD_NUMBER.toInteger()) {
echo "Aborting older running build " + build
echo 'Aborting older running build ' + build
build.doStop()
}
}
}
}

def startBraveBrowserBuild() {
PIPELINE_NAME = "pr-brave-browser-" + BRAVE_CORE_BRANCH.replace('/', '-')
PIPELINE_NAME = 'pr-brave-browser-' + CHANGE_BRANCH.replace('/', '-')
jobDsl(scriptText: """
pipelineJob("${PIPELINE_NAME}") {
pipelineJob('${PIPELINE_NAME}') {
// this list has to match the parameters in the Jenkinsfile from devops repo
parameters {
choiceParam("CHANNEL", ["nightly", "dev", "beta", "release", "development"])
choiceParam("BUILD_TYPE", ["Release", "Debug"])
booleanParam("WIPE_WORKSPACE", false)
booleanParam("SKIP_INIT", false)
booleanParam("DISABLE_SCCACHE", false)
booleanParam("SKIP_SIGNING", true)
booleanParam("DCHECK_ALWAYS_ON", true)
booleanParam("RUN_NETWORK_AUDIT", false)
booleanParam("SKIP_ANDROID", false)
booleanParam("SKIP_IOS", false)
booleanParam("SKIP_LINUX", false)
booleanParam("SKIP_MACOS", false)
booleanParam("SKIP_WINDOWS", false)
stringParam("BRAVE_BROWSER_BRANCH", "master")
stringParam("BRAVE_CORE_BRANCH", "master")
stringParam("BASE_BRANCH", "master")
stringParam("SLACK_USERNAME", "")
stringParam("SLACK_BUILDS_CHANNEL", "")
stringParam("BRANCH_PRODUCTIVITY_HOMEPAGE", "")
stringParam("BRANCH_PRODUCTIVITY_NAME", "")
stringParam("BRANCH_PRODUCTIVITY_DESCRIPTION", "")
stringParam("BRANCH_PRODUCTIVITY_USER", "")
choiceParam('CHANNEL', ['nightly', 'dev', 'beta', 'release', 'development'])
choiceParam('BUILD_TYPE', ['Release', 'Debug'])
booleanParam('WIPE_WORKSPACE', false)
booleanParam('SKIP_INIT', false)
booleanParam('DISABLE_SCCACHE', false)
booleanParam('SKIP_SIGNING', true)
booleanParam('DCHECK_ALWAYS_ON', true)
booleanParam('RUN_NETWORK_AUDIT', false)
booleanParam('SKIP_ANDROID', false)
booleanParam('SKIP_IOS', false)
booleanParam('SKIP_LINUX', false)
booleanParam('SKIP_MACOS', false)
booleanParam('SKIP_WINDOWS', false)
stringParam('BRANCH', '${CHANGE_BRANCH}')
}
definition {
cpsScm {
Expand All @@ -175,28 +151,23 @@ def startBraveBrowserBuild() {
}
""")
params = [
string(name: "CHANNEL", value: CHANNEL),
string(name: "BUILD_TYPE", value: BUILD_TYPE),
booleanParam(name: "WIPE_WORKSPACE", value: WIPE_WORKSPACE),
booleanParam(name: "SKIP_INIT", value: SKIP_INIT),
booleanParam(name: "DISABLE_SCCACHE", value: DISABLE_SCCACHE),
booleanParam(name: "SKIP_SIGNING", value: SKIP_SIGNING),
booleanParam(name: "DCHECK_ALWAYS_ON", value: DCHECK_ALWAYS_ON),
booleanParam(name: "RUN_NETWORK_AUDIT", value: RUN_NETWORK_AUDIT),
booleanParam(name: "SKIP_ANDROID", value: SKIP_ANDROID),
booleanParam(name: "SKIP_IOS", value: SKIP_IOS),
booleanParam(name: "SKIP_LINUX", value: SKIP_LINUX),
booleanParam(name: "SKIP_MACOS", value: SKIP_MACOS),
booleanParam(name: "SKIP_WINDOWS", value: SKIP_WINDOWS),
string(name: "BRAVE_BROWSER_BRANCH", value: BRAVE_BROWSER_BRANCH),
string(name: "BRAVE_CORE_BRANCH", value: BRAVE_CORE_BRANCH),
string(name: "BASE_BRANCH", value: BASE_BRANCH),
string(name: "SLACK_USERNAME", value: SLACK_USERNAME),
string(name: "SLACK_BUILDS_CHANNEL", value: '#build-downloads-bot'),
string(name: "BRANCH_PRODUCTIVITY_HOMEPAGE", value: BRANCH_PRODUCTIVITY_HOMEPAGE),
string(name: "BRANCH_PRODUCTIVITY_NAME", value: BRANCH_PRODUCTIVITY_NAME),
string(name: "BRANCH_PRODUCTIVITY_DESCRIPTION", value: BRANCH_PRODUCTIVITY_DESCRIPTION),
string(name: "BRANCH_PRODUCTIVITY_USER", value: BRANCH_PRODUCTIVITY_USER)
string(name: 'CHANNEL', value: params.CHANNEL),
string(name: 'BUILD_TYPE', value: params.BUILD_TYPE),
booleanParam(name: 'WIPE_WORKSPACE', value: params.WIPE_WORKSPACE),
booleanParam(name: 'SKIP_INIT', value: params.SKIP_INIT),
booleanParam(name: 'DISABLE_SCCACHE', value: params.DISABLE_SCCACHE),
booleanParam(name: 'SKIP_SIGNING', value: params.SKIP_SIGNING),
booleanParam(name: 'DCHECK_ALWAYS_ON', value: params.DCHECK_ALWAYS_ON),
booleanParam(name: 'RUN_NETWORK_AUDIT', value: RUN_NETWORK_AUDIT),
booleanParam(name: 'SKIP_ANDROID', value: SKIP_ANDROID),
booleanParam(name: 'SKIP_IOS', value: SKIP_IOS),
booleanParam(name: 'SKIP_LINUX', value: SKIP_LINUX),
booleanParam(name: 'SKIP_MACOS', value: SKIP_MACOS),
booleanParam(name: 'SKIP_WINDOWS', value: SKIP_WINDOWS),
string(name: 'BRANCH', value: CHANGE_BRANCH)
]
currentBuild.result = build(job: PIPELINE_NAME, parameters: params, propagate: false).result
if (env.OTHER_PR_NUMBER) {
build(job: OTHER_REPO + '-build-pr/PR-' + env.OTHER_PR_NUMBER, parameters: [string(name: 'BUILD_STATUS', value: currentBuild.result)], propagate: false)
}
}

0 comments on commit ad11ce6

Please sign in to comment.