Commit b26f0eeb authored by Clemens Lange's avatar Clemens Lange
Browse files

Merge branch 'on_success' into 'master'

on_success and on_failure

Closes #22

See merge request cms-cloud/cmssw-docker!19
parents 66d3217f 2bd87f36
stages:
- check
- build
- clean_up
# Triggered when the latest commit contains changes to cms/cvmfs/standalone
# Triggers the pipeline for every folder containing changes
......@@ -8,7 +9,7 @@ check_changes_pipeline:
stage: check
rules:
- changes: [cc7-cms/*, cc7-cvmfs/*, slc6-cms/*, slc6-cvmfs/*, slc5-cms/*, standalone/*]
if: $CI_PIPELINE_SOURCE == 'push' # Trigger if push (for test on branches) or merge event (for production on master)
if: $CI_PIPELINE_SOURCE == 'push' # Trigger if push (for test on branches)
tags:
- docker # tags docker since those runners have git installed (needed by check.sh)
script:
......@@ -60,6 +61,10 @@ check_changes_pipeline:
- printf "Release - $RELEASE\nScram Arch - $SCRAM_ARCH\nBase image - $BASE_IMAGE\n"
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR/$REPO_NAME --dockerfile $CI_PROJECT_DIR/$REPO_NAME/Dockerfile --destination $CI_REGISTRY_IMAGE/$IMAGE_NAME:$DATE-$CI_COMMIT_SHORT_SHA --build-arg=BUILD_DATE="$DATE" --build-arg=VERSION="$DATE" --build-arg=VCS_URL="$CI_REPOSITORY_URL" --build-arg=VCS_REF="$CI_COMMIT_SHORT_SHA" --build-arg BASEIMAGE="$BASE_IMAGE" --build-arg SCRAM_ARCH="$SCRAM_ARCH" --build-arg CMSSW_VERSION="$RELEASE"
- echo "export IMAGE_PATH=$CI_REGISTRY_IMAGE/$IMAGE_NAME:$DATE-$CI_COMMIT_SHORT_SHA" > standalone_image_path.env
artifacts:
paths:
- standalone_image_path.env # Pass image path to clean_up job
test_all_pipeline:
<<: *test_all
......@@ -99,4 +104,32 @@ build_standalone_pipeline:
REPO_NAME: standalone
BASE_IMAGE: "$CI_REGISTRY_IMAGE/$OS-cms:latest"
# Necessary variables to be passed to Dockerfile for building a standalone image is CMSSW_VERSION=$RELEASE,
# SCRAM_ARCH=$SCRAM_ARCH and BASEIMAGE="gitlab-registry.cern.ch/cms-cloud/cmssw-docker/$OS-cms:latest"
\ No newline at end of file
# SCRAM_ARCH=$SCRAM_ARCH and BASEIMAGE="gitlab-registry.cern.ch/cms-cloud/cmssw-docker/$OS-cms:latest"
# On success of standalone build remove labels and close corresponding Gitlab issue
# If email provided send an email notification
standalone_build_success:
stage: clean_up
only:
variables:
- $RELEASE && $SCRAM_ARCH && $OS && $ISSUE_IID
refs:
- master
when: on_success
script:
- "curl -X PUT -H PRIVATE-TOKEN:${GITLAB_TOKEN} https://gitlab.cern.ch/api/v4/projects/${BACKEND_IID}/issues/${ISSUE_IID}?state_event=close&labels=" # close and remove labels
- source standalone_image_path.env
- if ! [[ -z $EMAIL ]]; then curl -X POST -H Content-Type:application/json -H X-Gitlab-Token:${API_TOKEN} -d '{"recipient_email":"'"${EMAIL}"'","image_path":"'"${IMAGE_PATH}"'"}' ${BACKEND_URL}/email; fi # send email notification
# On failure change label of corresponding Gitlab issue and comment on issue
standalone_build_failure:
stage: clean_up
only:
variables:
- $RELEASE && $SCRAM_ARCH && $OS && $ISSUE_IID
refs:
- master
when: on_failure
script:
- "curl -X PUT -H PRIVATE-TOKEN:${GITLAB_TOKEN} https://gitlab.cern.ch/api/v4/projects/${BACKEND_IID}/issues/${ISSUE_IID}?labels=Pipeline%20failed" # change label
- "curl -X POST -H PRIVATE-TOKEN:${GITLAB_TOKEN} https://gitlab.cern.ch/api/v4/projects/${BACKEND_IID}/issues/${ISSUE_IID}/notes?body=The%20pipeline%20of%20this%20request%20just%20failed" # comment on issue
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment