Skip to content

Commit

Permalink
chore: use pipeline step
Browse files Browse the repository at this point in the history
  • Loading branch information
kuisathaverat committed Mar 31, 2021
1 parent ddfe503 commit 06bde94
Showing 1 changed file with 0 additions and 49 deletions.
49 changes: 0 additions & 49 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -1018,52 +1018,3 @@ class GetProjectDependencies extends co.elastic.beats.BeatsFunction {
return output?.split('\n').collect{ item -> item as String }
}
}

/**
Execute the body if there is not stage status file for the stage and the commit we are building.
User triggered builds will execute all stages always.
If the stage success the status is save in a file.
*/
def stageStatusCache(Map args, Closure body){
if(readStageStatus(args) == false || isUserTrigger() || env.BUILD_ID == "1"){
body()
saveStageStatus(args)
} else {
log(level: 'INFO', text: "The stage skiped because it is in the execution cache.")
}
}

/**
Save the status file of the stage.
*/
def saveStageStatus(Map args){
def statusFileName = stageStatusId(args)
writeFile(file: statusFileName, text: "OK")
googleStorageUploadExt(bucket: "gs://${JOB_GCS_BUCKET}/ci/cache/",
credentialsId: "${JOB_GCS_EXT_CREDENTIALS}",
pattern: "${statusFileName}",
sharedPublicly: true)
}

/**
Read the status file of the stage if it exists.
*/
def readStageStatus(Map args){
def statusFileName = stageStatusId(args)
try {
cmd(label: 'Download Stage Status',
script: "curl -sSf -O https://storage.googleapis.com/${JOB_GCS_BUCKET}/ci/cache/${statusFileName}",
returnStatus: true)
} catch(e) {
log(level: 'WARN', text: "There is no cache file for the current stage.")
} finally {
return fileExists("${statusFileName}")
}
}

/**
generate an unique ID for the stage and commit.
*/
def stageStatusId(Map args){
return base64encode(text: "${args.id}${GIT_BASE_COMMIT}", encoding: "UTF-8")
}

0 comments on commit 06bde94

Please sign in to comment.