Add use of post build info json
This commit is contained in:
parent
ba2fa8cd05
commit
535076b3e3
3 changed files with 127 additions and 71 deletions
|
|
@ -1,79 +1,101 @@
|
|||
/* Example post build info
|
||||
{
|
||||
"Build outcomes": {
|
||||
"Success": {
|
||||
"Actions": {
|
||||
"Deploy doxygen": {
|
||||
"Description": "Can be empty - Name of doxygen deploy job to run if this build is successful",
|
||||
"Job": "HMB_FD_HV_0.9.6/HMB_FD_HV_0.9.6_sg1024_doxygen_deploy"
|
||||
},
|
||||
"Static analysis": {
|
||||
"Description": "Can be empty - Static analysis job to run when this build is successful",
|
||||
"Job": ""
|
||||
},
|
||||
"Unit test": {
|
||||
"Description": "Can be empty - Unit test job to run when this build is successful",
|
||||
"Job": ""
|
||||
},
|
||||
"Regression test": {
|
||||
"Description": "Can be empty - Regression test job to run when this build is successful",
|
||||
"Job": "HMB_FD_HV_0.9.6/HMB_FD_HV_0.9.6_sg1024_run_tests"
|
||||
},
|
||||
"Update differences": {
|
||||
"Description": "Can be empty - Update differences job to run when this build is successful",
|
||||
"Job": "HMB_FD_HV_diff_releases"
|
||||
},
|
||||
"Release to git": {
|
||||
"Description": "Can be empty - Name of release to git job to run if this build is successful",
|
||||
"Job": "HMB_FD_HV_release_to_git"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
def performSuccessfulBuildActions() {
|
||||
def String buildselector = "<SpecificBuildSelector plugin='copyartifact@1.46.2'><buildNumber>${BUILD_NUMBER}</buildNumber></SpecificBuildSelector>"
|
||||
if (params.DOXYGEN_DEPLOY_JOB != null) {
|
||||
if (DOXYGEN_DEPLOY_JOB && Jenkins.instance.getItemByFullName(DOXYGEN_DEPLOY_JOB).isBuildable()) {
|
||||
build(
|
||||
wait: false,
|
||||
job: DOXYGEN_DEPLOY_JOB,
|
||||
parameters: [
|
||||
string(name: 'BUILD_JOB_WITH_DOXYGEN_ARTIFACTS', value: JOB_NAME),
|
||||
string(name: 'BUILD_JOB_WITH_DOXYGEN_ARTIFACTS_SELECTOR', value: buildselector),
|
||||
]
|
||||
)
|
||||
}
|
||||
def getActionJobName(postbuildactions, String action, String alternativeparamname) {
|
||||
def String jobname
|
||||
if (postbuildactions) {
|
||||
jobname = postbuildactions[action]['Job']
|
||||
} else {
|
||||
if (params[alternativeparam] != null) {
|
||||
if (params[alternativeparam]) {
|
||||
jobname = params[alternativeparam]
|
||||
}
|
||||
}
|
||||
}
|
||||
if (params.STATIC_ANALYSIS_JOB != null) {
|
||||
if (STATIC_ANALYSIS_JOB && Jenkins.instance.getItemByFullName(STATIC_ANALYSIS_JOB).isBuildable()) {
|
||||
build(
|
||||
wait: false,
|
||||
job: STATIC_ANALYSIS_JOB,
|
||||
parameters: [
|
||||
string(name: 'APPLICATION_ARTIFACT_PROJECT', value: JOB_NAME),
|
||||
string(name: 'APPLICATION_ARTIFACT_SELECTOR', value: buildselector),
|
||||
]
|
||||
)
|
||||
def jobitem = Jenkins.instance.getItemByFullName(jobname)
|
||||
if (jobitem) {
|
||||
if (!jobitem.isBuildable()) {
|
||||
jobname = ''
|
||||
}
|
||||
} else {
|
||||
jobname = ''
|
||||
}
|
||||
if (params.UNIT_TEST_JOB != null) {
|
||||
if (UNIT_TEST_JOB && Jenkins.instance.getItemByFullName(UNIT_TEST_JOB).isBuildable()) {
|
||||
build(
|
||||
wait: false,
|
||||
job: UNIT_TEST_JOB,
|
||||
parameters: [
|
||||
string(name: 'APPLICATION_ARTIFACT_PROJECT', value: JOB_NAME),
|
||||
string(name: 'APPLICATION_ARTIFACT_SELECTOR', value: buildselector),
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
if (params.REGRESSION_TEST_JOB != null) {
|
||||
if (REGRESSION_TEST_JOB && Jenkins.instance.getItemByFullName(REGRESSION_TEST_JOB).isBuildable()) {
|
||||
build(
|
||||
wait: false,
|
||||
job: REGRESSION_TEST_JOB,
|
||||
parameters: [
|
||||
string(name: 'APPLICATION_ARTIFACT_PROJECT', value: JOB_NAME),
|
||||
string(name: 'APPLICATION_ARTIFACT_SELECTOR', value: buildselector),
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
if (params.DIFF_JOB != null) {
|
||||
if (DIFF_JOB && Jenkins.instance.getItemByFullName(DIFF_JOB).isBuildable()) {
|
||||
build(
|
||||
wait: false,
|
||||
job: DIFF_JOB,
|
||||
parameters: [
|
||||
string(name: 'LATER_SOURCE', value: 'Jenkins job artifact'),
|
||||
string(name: 'LATER_BUILD_JOB', value: JOB_NAME),
|
||||
string(name: 'LATER_BUILD_SELECTOR', value: buildselector),
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
if (params.RELEASE_TO_GIT_JOB != null) {
|
||||
if (RELEASE_TO_GIT_JOB && Jenkins.instance.getItemByFullName(RELEASE_TO_GIT_JOB).isBuildable()) {
|
||||
build(
|
||||
wait: false,
|
||||
job: RELEASE_TO_GIT_JOB,
|
||||
parameters: [
|
||||
string(name: 'BUILD_JOB', value: JOB_NAME),
|
||||
string(name: 'BUILD_JOB_SELECTOR', value: buildselector),
|
||||
]
|
||||
)
|
||||
}
|
||||
return jobname
|
||||
}
|
||||
|
||||
|
||||
def deployjob(String buildselector, postbuildactions, String action, String alternativeparamname) {
|
||||
def jobname = getActionJobName(postbuildactions, action, alternativeparamname)
|
||||
if (jobname) {
|
||||
build(
|
||||
wait: false,
|
||||
job: jobname,
|
||||
parameters: [
|
||||
// For most jobs
|
||||
string(name: 'APPLICATION_ARTIFACT_PROJECT', value: JOB_NAME),
|
||||
string(name: 'APPLICATION_ARTIFACT_SELECTOR', value: buildselector),
|
||||
// For diff jobs
|
||||
string(name: 'LATER_SOURCE', value: 'Jenkins job artifact'),
|
||||
string(name: 'LATER_BUILD_JOB', value: JOB_NAME),
|
||||
string(name: 'LATER_BUILD_SELECTOR', value: buildselector),
|
||||
// For regression jobs
|
||||
string(name: 'BUILD_JOB', value: JOB_NAME),
|
||||
string(name: 'BUILD_JOB_SELECTOR', value: buildselector),
|
||||
]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
def performSuccessfulBuildActions() {
|
||||
def postbuildactions
|
||||
if (params.POST_BUILD_INFO != null) {
|
||||
def postbuildinfo = readJSON(text: POST_BUILD_INFO)
|
||||
def postbuildjsontext = writeJSON(returnText: true, json: postbuildinfo, pretty: 1)
|
||||
echo "Post build info:\n${postbuildjsontext}"
|
||||
postbuildactions = postbuildinfo['Build outcomes']['Success']['Action']
|
||||
postbuildinfoavailable = true
|
||||
}
|
||||
def String buildselector = "<SpecificBuildSelector plugin='copyartifact@1.46.2'><buildNumber>${BUILD_NUMBER}</buildNumber></SpecificBuildSelector>"
|
||||
deployjob(buildselector, postbuildactions, 'Deploy doxygen', 'DOXYGEN_DEPLOY_JOB')
|
||||
deployjob(buildselector, postbuildactions, 'Static analysis', 'STATIC_ANALYSIS_JOB')
|
||||
deployjob(buildselector, postbuildactions, 'Unit test', 'UNIT_TEST_JOB')
|
||||
deployjob(buildselector, postbuildactions, 'Regression test', 'REGRESSION_TEST_JOB')
|
||||
deployjob(buildselector, postbuildactions, 'Update differences', 'DIFF_JOB')
|
||||
deployjob(buildselector, postbuildactions, 'Release to git', 'RELEASE_TO_GIT_JOB')
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
|
|||
36
build/postactionstest.groovy
Normal file
36
build/postactionstest.groovy
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
pipeline {
|
||||
agent { label AGENT_LABEL }
|
||||
stages {
|
||||
stage('Initial setup') {
|
||||
steps {
|
||||
script {
|
||||
meta = load("${WORKSPACE}/autobuild/Common_scripts/autobuilder.groovy").startnonbuild(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
stage('Dummy build job') {
|
||||
steps {
|
||||
script {
|
||||
echo "Execute dummy build job"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
always {
|
||||
echo 'Post-build'
|
||||
}
|
||||
failure {
|
||||
echo 'Failed build'
|
||||
}
|
||||
unstable {
|
||||
echo 'Unstable build'
|
||||
}
|
||||
success {
|
||||
echo 'Succeeded build'
|
||||
script {
|
||||
load("${autobuilder.commonscripts()}/build/postactions.groovy").performSuccessfulBuildActions()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,8 +35,6 @@ def boolean exists() {
|
|||
|
||||
def set(String jsontext) {
|
||||
sominfostore = readJSON(text: jsontext)
|
||||
|
||||
def som_support_json_text = writeJSON(returnText: true, json: sominfostore, pretty: 1)
|
||||
echo "Som support info:\n${asJsonText()}"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue