Add overall timeout for the AR pipeline #7261

monroegm-disable-blank-issue-2
Brian Herrera 4 years ago committed by GitHub
commit 31f39930af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,6 +12,9 @@ INCREMENTAL_BUILD_SCRIPT_PATH = 'scripts/build/bootstrap/incremental_build_util.
EBS_SNAPSHOT_SCRIPT_PATH = 'scripts/build/tools/ebs_snapshot.py' EBS_SNAPSHOT_SCRIPT_PATH = 'scripts/build/tools/ebs_snapshot.py'
PIPELINE_RETRY_ATTEMPTS = 3 PIPELINE_RETRY_ATTEMPTS = 3
// Number of minutes of inactivity in all stages of the pipeline to reach the timeout
PIPELINE_TIMEOUT = 60
EMPTY_JSON = readJSON text: '{}' EMPTY_JSON = readJSON text: '{}'
ENGINE_REPOSITORY_NAME = 'o3de' ENGINE_REPOSITORY_NAME = 'o3de'
@ -753,143 +756,145 @@ def pipelineConfig = {}
// Start Pipeline // Start Pipeline
try { try {
stage('Setup Pipeline') { timeout(time: PIPELINE_TIMEOUT, unit: 'MINUTES', activity: true) {
node('controller') { stage('Setup Pipeline') {
def envVarList = [] node('controller') {
if(isUnix()) { def envVarList = []
envVarList.add('IS_UNIX=1') if(isUnix()) {
} envVarList.add('IS_UNIX=1')
withEnv(envVarList) { }
timestamps { withEnv(envVarList) {
repositoryUrl = scm.getUserRemoteConfigs()[0].getUrl() timestamps {
// repositoryName is the full repository name repositoryUrl = scm.getUserRemoteConfigs()[0].getUrl()
repositoryName = (repositoryUrl =~ /https:\/\/github.com\/(.*)\.git/)[0][1] // repositoryName is the full repository name
env.REPOSITORY_NAME = repositoryName repositoryName = (repositoryUrl =~ /https:\/\/github.com\/(.*)\.git/)[0][1]
(projectName, pipelineName) = GetRunningPipelineName(env.JOB_NAME) // env.JOB_NAME is the name of the job given by Jenkins env.REPOSITORY_NAME = repositoryName
env.PIPELINE_NAME = pipelineName (projectName, pipelineName) = GetRunningPipelineName(env.JOB_NAME) // env.JOB_NAME is the name of the job given by Jenkins
if(env.BRANCH_NAME) { env.PIPELINE_NAME = pipelineName
branchName = env.BRANCH_NAME if(env.BRANCH_NAME) {
} else { branchName = env.BRANCH_NAME
branchName = scm.branches[0].name // for non-multibranch pipelines
env.BRANCH_NAME = branchName // so scripts that read this environment have it (e.g. incremental_build_util.py)
}
if(env.CHANGE_TARGET) {
// PR builds
if(BUILD_SNAPSHOTS.contains(env.CHANGE_TARGET)) {
snapshot = env.CHANGE_TARGET
echo "Snapshot for destination branch \"${env.CHANGE_TARGET}\" found."
} else { } else {
snapshot = DEFAULT_BUILD_SNAPSHOT branchName = scm.branches[0].name // for non-multibranch pipelines
echo "Snapshot for destination branch \"${env.CHANGE_TARGET}\" does not exist, defaulting to snapshot \"${snapshot}\"" env.BRANCH_NAME = branchName // so scripts that read this environment have it (e.g. incremental_build_util.py)
} }
} else { if(env.CHANGE_TARGET) {
// Non-PR builds // PR builds
pipelineParameters.add(choice(defaultValue: DEFAULT_BUILD_SNAPSHOT, name: 'SNAPSHOT', choices: BUILD_SNAPSHOTS_WITH_EMPTY, description: 'Selects the build snapshot to use. A more diverted snapshot will cause longer build times, but will not cause build failures.')) if(BUILD_SNAPSHOTS.contains(env.CHANGE_TARGET)) {
snapshot = env.SNAPSHOT snapshot = env.CHANGE_TARGET
echo "Snapshot \"${snapshot}\" selected." echo "Snapshot for destination branch \"${env.CHANGE_TARGET}\" found."
} } else {
pipelineProperties.add(disableConcurrentBuilds()) snapshot = DEFAULT_BUILD_SNAPSHOT
echo "Snapshot for destination branch \"${env.CHANGE_TARGET}\" does not exist, defaulting to snapshot \"${snapshot}\""
}
} else {
// Non-PR builds
pipelineParameters.add(choice(defaultValue: DEFAULT_BUILD_SNAPSHOT, name: 'SNAPSHOT', choices: BUILD_SNAPSHOTS_WITH_EMPTY, description: 'Selects the build snapshot to use. A more diverted snapshot will cause longer build times, but will not cause build failures.'))
snapshot = env.SNAPSHOT
echo "Snapshot \"${snapshot}\" selected."
}
pipelineProperties.add(disableConcurrentBuilds())
echo "Running repository: \"${repositoryName}\", pipeline: \"${pipelineName}\", branch: \"${branchName}\", CHANGE_ID: \"${env.CHANGE_ID}\", GIT_COMMMIT: \"${scm.GIT_COMMIT}\"..." echo "Running repository: \"${repositoryName}\", pipeline: \"${pipelineName}\", branch: \"${branchName}\", CHANGE_ID: \"${env.CHANGE_ID}\", GIT_COMMMIT: \"${scm.GIT_COMMIT}\"..."
CheckoutBootstrapScripts(branchName) CheckoutBootstrapScripts(branchName)
// Load configs // Load configs
pipelineConfig = LoadPipelineConfig(pipelineName, branchName) pipelineConfig = LoadPipelineConfig(pipelineName, branchName)
// Add each platform as a parameter that the user can disable if needed // Add each platform as a parameter that the user can disable if needed
if (!IsPullRequest(branchName)) { if (!IsPullRequest(branchName)) {
pipelineParameters.add(stringParam(defaultValue: '', description: 'Filters and overrides the list of jobs to run for each of the below platforms (comma-separated). Can\'t be used during a pull request.', name: 'JOB_LIST_OVERRIDE')) pipelineParameters.add(stringParam(defaultValue: '', description: 'Filters and overrides the list of jobs to run for each of the below platforms (comma-separated). Can\'t be used during a pull request.', name: 'JOB_LIST_OVERRIDE'))
pipelineConfig.platforms.each { platform -> pipelineConfig.platforms.each { platform ->
pipelineParameters.add(booleanParam(defaultValue: true, description: '', name: platform.key)) pipelineParameters.add(booleanParam(defaultValue: true, description: '', name: platform.key))
}
}
// Add additional Jenkins parameters
pipelineConfig.platforms.each { platform ->
platformEnv = platform.value.PIPELINE_ENV
pipelineJenkinsParameters = platformEnv['PIPELINE_JENKINS_PARAMETERS'] ?: [:]
jenkinsParametersToAdd = pipelineJenkinsParameters[pipelineName] ?: [:]
jenkinsParametersToAdd.each{ jenkinsParameter ->
defaultValue = jenkinsParameter['default_value']
// Use last run's value as default value so we can save values in different Jenkins environment
if (jenkinsParameter['use_last_run_value']?.toBoolean()) {
defaultValue = params."${jenkinsParameter['parameter_name']}" ?: jenkinsParameter['default_value']
} }
switch (jenkinsParameter['parameter_type']) { }
case 'string': // Add additional Jenkins parameters
pipelineParameters.add(stringParam(defaultValue: defaultValue, pipelineConfig.platforms.each { platform ->
description: jenkinsParameter['description'], platformEnv = platform.value.PIPELINE_ENV
name: jenkinsParameter['parameter_name'] pipelineJenkinsParameters = platformEnv['PIPELINE_JENKINS_PARAMETERS'] ?: [:]
)) jenkinsParametersToAdd = pipelineJenkinsParameters[pipelineName] ?: [:]
break jenkinsParametersToAdd.each{ jenkinsParameter ->
case 'boolean': defaultValue = jenkinsParameter['default_value']
pipelineParameters.add(booleanParam(defaultValue: defaultValue, // Use last run's value as default value so we can save values in different Jenkins environment
description: jenkinsParameter['description'], if (jenkinsParameter['use_last_run_value']?.toBoolean()) {
name: jenkinsParameter['parameter_name'] defaultValue = params."${jenkinsParameter['parameter_name']}" ?: jenkinsParameter['default_value']
)) }
break switch (jenkinsParameter['parameter_type']) {
case 'password': case 'string':
pipelineParameters.add(password(defaultValue: defaultValue, pipelineParameters.add(stringParam(defaultValue: defaultValue,
description: jenkinsParameter['description'], description: jenkinsParameter['description'],
name: jenkinsParameter['parameter_name'] name: jenkinsParameter['parameter_name']
)) ))
break break
case 'boolean':
pipelineParameters.add(booleanParam(defaultValue: defaultValue,
description: jenkinsParameter['description'],
name: jenkinsParameter['parameter_name']
))
break
case 'password':
pipelineParameters.add(password(defaultValue: defaultValue,
description: jenkinsParameter['description'],
name: jenkinsParameter['parameter_name']
))
break
}
} }
} }
}
pipelineProperties.add(parameters(pipelineParameters.unique())) pipelineProperties.add(parameters(pipelineParameters.unique()))
properties(pipelineProperties) properties(pipelineProperties)
// Stash the INCREMENTAL_BUILD_SCRIPT_PATH and EBS_SNAPSHOT_SCRIPT_PATH since all nodes will use it // Stash the INCREMENTAL_BUILD_SCRIPT_PATH and EBS_SNAPSHOT_SCRIPT_PATH since all nodes will use it
stash name: 'incremental_build_script', stash name: 'incremental_build_script',
includes: INCREMENTAL_BUILD_SCRIPT_PATH includes: INCREMENTAL_BUILD_SCRIPT_PATH
if (fileExists(EBS_SNAPSHOT_SCRIPT_PATH)) { if (fileExists(EBS_SNAPSHOT_SCRIPT_PATH)) {
stash name: 'ebs_snapshot_script', stash name: 'ebs_snapshot_script',
includes: EBS_SNAPSHOT_SCRIPT_PATH includes: EBS_SNAPSHOT_SCRIPT_PATH
}
} }
} }
} }
} }
}
if(env.BUILD_NUMBER == '1' && !IsPullRequest(branchName)) { if(env.BUILD_NUMBER == '1' && !IsPullRequest(branchName)) {
// Exit pipeline early on the intial build. This allows Jenkins to load the pipeline for the branch and enables users // Exit pipeline early on the intial build. This allows Jenkins to load the pipeline for the branch and enables users
// to select build parameters on their first actual build. See https://issues.jenkins.io/browse/JENKINS-41929 // to select build parameters on their first actual build. See https://issues.jenkins.io/browse/JENKINS-41929
currentBuild.result = 'SUCCESS' currentBuild.result = 'SUCCESS'
return return
} }
def someBuildHappened = false def someBuildHappened = false
// Build and Post-Build Testing Stage // Build and Post-Build Testing Stage
def buildConfigs = [:] def buildConfigs = [:]
// Platform Builds run on EC2 // Platform Builds run on EC2
pipelineConfig.platforms.each { platform -> pipelineConfig.platforms.each { platform ->
platform.value.build_types.each { build_job -> platform.value.build_types.each { build_job ->
if (IsJobEnabled(branchName, build_job, pipelineName, platform.key)) { // User can filter jobs, jobs are tagged by pipeline if (IsJobEnabled(branchName, build_job, pipelineName, platform.key)) { // User can filter jobs, jobs are tagged by pipeline
def envVars = GetBuildEnvVars(platform.value.PIPELINE_ENV ?: EMPTY_JSON, build_job.value.PIPELINE_ENV ?: EMPTY_JSON, pipelineName) def envVars = GetBuildEnvVars(platform.value.PIPELINE_ENV ?: EMPTY_JSON, build_job.value.PIPELINE_ENV ?: EMPTY_JSON, pipelineName)
envVars['JENKINS_JOB_NAME'] = env.JOB_NAME // Save original Jenkins job name to JENKINS_JOB_NAME envVars['JENKINS_JOB_NAME'] = env.JOB_NAME // Save original Jenkins job name to JENKINS_JOB_NAME
envVars['JOB_NAME'] = "${branchName}_${platform.key}_${build_job.key}" // backwards compatibility, some scripts rely on this envVars['JOB_NAME'] = "${branchName}_${platform.key}_${build_job.key}" // backwards compatibility, some scripts rely on this
someBuildHappened = true someBuildHappened = true
buildConfigs["${platform.key} [${build_job.key}]"] = CreateBuildJobs(pipelineConfig, platform, build_job, envVars, branchName, pipelineName, repositoryName, projectName) buildConfigs["${platform.key} [${build_job.key}]"] = CreateBuildJobs(pipelineConfig, platform, build_job, envVars, branchName, pipelineName, repositoryName, projectName)
}
} }
} }
}
timestamps { timestamps {
stage('Build') { stage('Build') {
parallel buildConfigs // Run parallel builds parallel buildConfigs // Run parallel builds
} }
echo 'All builds successful' echo 'All builds successful'
} }
if (!someBuildHappened) { if (!someBuildHappened) {
currentBuild.result = 'NOT_BUILT' currentBuild.result = 'NOT_BUILT'
}
} }
} }
catch(Exception e) { catch(Exception e) {

Loading…
Cancel
Save