Skip to content

Add script/after script timeout configuration via variables

Arran Walker requested to merge ajwalker/add-script-timeout into main

What does this MR do?

Adds the ability to control the timeout for the script sections of a job via a RUNNER_SCRIPT_TIMEOUT and RUNNER_AFTER_SCRIPT_TIMEOUT job variable.

Warnings are shown where a timeout would exceed the job's timeout.

Example uses:

.common-job:
  script:
    - echo "running forever"
    - echo "hello" > file
    - sleep 300
  artifacts:
    paths:
      - file
    when: always

absolute-timeout:
  variables:
    RUNNER_SCRIPT_TIMEOUT: 1m # leaves 1 minute of script execution
  extends: .common-job

exceed-job-timeout:
  variables:
    RUNNER_SCRIPT_TIMEOUT: 2h # ignores timeout, but warns that it would exceed job timeout
  extends: .common-job

Why was this MR needed?

Reason for RUNNER_SCRIPT_TIMEOUT: Jobs that use fuzz testing would like the job script to terminate before the job timeout, allowing enough time for artifacts to be uploaded.

Reason for RUNNER_AFTER_SCRIPT_TIMEOUT: A hard-coded 5 minutes wasn't suitable for everyone. Users would often be confused about how errors were handled.

What's the best way to test this MR?

Run the above examples.

Integration tests and unit tests have been added.

What are the relevant issue numbers?

Closes gitlab#284186 (closed)

Closes #2716 (closed)

Closes gitlab#421691 (closed)

Edited by Arran Walker

Merge request reports