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

feat: add hook scripts support

parent 02863198
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -69,3 +69,10 @@ or through a basic `environment_url.txt` file, then the Hurl test will automatic
environments) will automatically be propagated to your Hurl tests.

When successfully determined, the base url is then [injected as `base_url` variable](https://hurl.dev/docs/templates.html#injecting-variables), and can be freely used in your Hurl scripts with the `{{base_url}}` expression.

### Hook scripts

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

* `pre-hurl.sh` is executed **before** running Hurl,
* `post-hurl.sh` is executed **after** running Hurl (whichever the tests status).
+20 −8
Original line number Diff line number Diff line
@@ -323,7 +323,10 @@ stages:
    done
  }

  function exec_hook() {
  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)"
@@ -332,7 +335,9 @@ stages:
      else
        "$1"
      fi
    fi
  }

  # retrieve server url to test from upstream artifacts ($environment_url variable or 'environment_url.txt' file)
  function eval_env_url() {
    # shellcheck disable=SC2154
@@ -372,7 +377,14 @@ hurl:
    - eval_env_url
  script:
    - mkdir -p -m 777 reports
    - hurl ${TRACE+--verbose} --test --report-junit reports/hurl.xunit.xml $HURL_EXTRA_ARGS $HURL_TEST_FILES
    # maybe execute pre hook
    - maybe_exec_hook "./pre-hurl.sh"
    # run tests
    - hurl ${TRACE+--verbose} --test --report-junit reports/hurl.xunit.xml $HURL_EXTRA_ARGS $HURL_TEST_FILES || rc=$?
    # maybe execute post hook
    - maybe_exec_hook "./post-hurl.sh"
    # exit with return code
    - exit $rc
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    when: always