message: Increment an index if dir already exists
diff: # Default is to run if previous stage succeeded
  - when: on_success
  +# This is a yaml anchor, it can be used to avoid duplication like here.
  +# The code below will simply be pasted wherever the anchor is placed.
  +.safe_create_rundir: &safe_create_rundir |
  + if ! mkdir ${rundir}; then
  + n=1
  + while ! mkdir ${rundir}_${n}
  + do
  + n=$((n+1))
  + done
  +
  # Allocate
  q_allocate_resources:
  variables:
  @@ -65,10 +75,9 @@ q_report_success:
  stage: q_release_resources
  script:
  - echo "Can only run if all the quartz jobs passed"
  - - rundir="gitlab/$(date +%Y-%m-%d)-github-${CI_COMMIT_REF_SLUG}"
  - cd ${AUTOTEST_ROOT}/autotest && git pull
  - - ([[ -d "${rundir}" ]] && git rm -r ${rundir})
  - - mkdir -p ${rundir}
  + - rundir="gitlab/$(date +%Y-%m-%d)-github-${CI_COMMIT_REF_SLUG}"
  + - *safe_create_rundir
  - echo "The Quartz jobs were successful" > ${rundir}/gitlab.out
  - echo "See the pipeline here: $CI_PIPELINE_URL" >> ${rundir}/gitlab.err
  - git add ${rundir}
  @@ -82,10 +91,9 @@ q_report_failure:
  stage: q_release_resources
  script:
  - echo "Runs if there was at least one failure on quartz"
  - - rundir="gitlab/$(date +%Y-%m-%d)-github-${CI_COMMIT_REF_SLUG}"
  - cd ${AUTOTEST_ROOT}/autotest && git pull
  - - ([[ -d "${rundir}" ]] && git rm -r ${rundir})
  - - mkdir -p ${rundir}
  + - rundir="gitlab/$(date +%Y-%m-%d)-github-${CI_COMMIT_REF_SLUG}"
  + - *safe_create_rundir
  - echo "There was an error while running CI on Quartz" > ${rundir}/gitlab.err
  - echo "See the pipeline here: $CI_PIPELINE_URL" >> ${rundir}/gitlab.err
  - cp ${rundir}/gitlab.err ${rundir}/autotest-email.html
  @@ -150,10 +158,9 @@ update_autotest:
  needs: [baselinecheck_mfem_intel_quartz]
  stage: baseline_to_autotest
  script:
  - - rundir="quartz/$(date +%Y-%m-%d)-github-${CI_COMMIT_REF_SLUG}"
  - cd ${AUTOTEST_ROOT}/autotest && git pull
  - - ([[ -d "${rundir}" ]] && git rm -r ${rundir})
  - - mkdir -p ${rundir}
  + - rundir="quartz/$(date +%Y-%m-%d)-github-${CI_COMMIT_REF_SLUG}"
  + - *safe_create_rundir
  - cp ${CI_PROJECT_DIR}/${ARTIFACTS_DIR}/* ${rundir}
  # We create an autotest-email.html file, because that's how we signal that there was a diff (temporary).
  - |
  