Commit b13b8e44 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: add hook scripts support

parent ac8fcbe8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -71,3 +71,10 @@ or through a basic `environment_url.txt` file, then the Postman test will automa

:warning: all our deployment templates implement this design. Therefore even purely dynamic environments (such as review
environments) will automatically be propagated to your Postman tests.

### Hook scripts

The Postman template supports _optional_ **hook scripts** from your project, located in the root directory to perform additional project-specific logic:

* `pre-postman.sh` is executed **before** running Postman,
* `post-postman.sh` is executed **after** running Postman (whichever the tests status).
+27 −1
Original line number Diff line number Diff line
@@ -232,6 +232,21 @@ stages:
    log_info "... done"
  }

  function maybe_exec_hook() {
    if [[ -f "$1" ]]
    then
      log_info "\\e[33;1m$1\\e[0m hook found: execute"
      if [[ ! -x "$1" ]] && ! chmod +x "$1"
      then
        log_warn "... could not make \\e[33;1m${1}\\e[0m executable: please do it (chmod +x)"
        # fallback technique
        sh "$1"
      else
        "$1"
      fi
    fi
  }

  function eval_base_url() {
    # shellcheck disable=SC2154
    if [[ -n "$environment_url" ]]
@@ -270,13 +285,24 @@ postman:
    - eval_base_url
  script:
    - mkdir -p -m 777 reports
    # maybe execute pre hook
    - maybe_exec_hook "./pre-postman.sh"
    # run tests
    - |
      for collection in $POSTMAN_COLLECTIONS
      do
        log_info "Running collection \\e[33;1m${collection}\\e[0m..."
        namenoext=$(basename $collection | sed 's/\..*//')
        newman run $base_url_opt $ca_certs_opt ${TRACE+--verbose} --reporters cli,junit --reporter-junit-export reports/postman-$namenoext.xunit.xml $POSTMAN_EXTRA_ARGS "$collection"
        if ! newman run $base_url_opt $ca_certs_opt ${TRACE+--verbose} --reporters cli,junit --reporter-junit-export reports/postman-$namenoext.xunit.xml $POSTMAN_EXTRA_ARGS "$collection"
        then
          log_error "Collection \\e[33;1m./${collection}\\e[0m failed"
          rc=127
        fi
      done
    # maybe execute post hook
    - maybe_exec_hook "./post-postman.sh"
    # exit with return code
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always