Auto_stop_in based on variable

Auto Store Settings / Based on Criteria

We are working through an issue I was hoping to get some advice / ideas on the best way to solve.

In our pipeline we currently have environments in NonProduction scheduled to stop after an hour of no commit activity. This is working great but we want to expand this based on rules that would allow us to extend this time when the environment is being used by QA, etc.

Here is our current setting.

  environment:
    name: review/$CI_COMMIT_REF_NAME
    on_stop: stop_review
    auto_stop_in: 1 hour

When I replace “1 hour” with a variable Gitlab throws an exception stating the value must be a duration.

I have tried putting rules on the “stop_review” job but it doesn’t seem to respect them with this setup (i.e. stop_review still runs and destroys the environment after an hour).

For example:

  rules:
    - if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != "master" && $REVIEW_ENVIRONMENT == "true"'
      when: never
    - if: '$CI_COMMIT_BRANCH && $CI_COMMIT_BRANCH != "master" && $REVIEW_ENVIRONMENT == "false"'
      when: manual        
    - when: never 

Any thoughts around best practice for handling this type of setup would be greatly appreciated. Thanks!

1 Like