# Scenario Book for Jira — GitLab CI. # # Include from your .gitlab-ci.yml and copy scenario-book-sync.mjs anywhere in the repo: # # include: # - local: 'docs/pipeline/gitlab-ci.yml' # # Set the variables from README.md under Settings → CI/CD → Variables, with "Masked" on SB_SYNC_KEY and # JIRA_API_TOKEN. Mark them "Protected" only if the pull branch is protected too, or the scheduled job # cannot see them. SB_GIT_TOKEN is a project access token with write_repository — the job token cannot push. .scenario-book-base: image: node:20 # Deliberately not interruptible: a pull killed half way may have written some of Jira's files and not # others, and the next run would send Jira that mixture as though it were the repository. interruptible: false scenario-book-pull: extends: .scenario-book-base stage: .pre # Scheduled only (Build → Pipeline schedules). Jira is the side people edit in, so this is how fast their # changes reach the repo. rules: - if: $CI_PIPELINE_SOURCE == "schedule" variables: SB_DIR: features GIT_STRATEGY: clone script: - node scenario-book-sync.mjs pull # A branch and a merge request rather than a commit to the default branch: a scenario arriving from Jira # changes what the tests assert, so it goes through review like any other change. - | if [ -n "$(git status --porcelain)" ]; then git config user.name "Scenario Book sync" git config user.email "scenario-book@${CI_SERVER_HOST}" git checkout -B scenario-book/from-jira git add -A git commit -m "Scenario Book: feature files from Jira" git push --force \ -o merge_request.create \ -o merge_request.title="Scenario Book: feature files from Jira" \ "https://oauth2:${SB_GIT_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" scenario-book/from-jira else echo "Nothing changed." fi scenario-book-push: extends: .scenario-book-base stage: .post rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE != "schedule" variables: SB_DIR: features script: - node scenario-book-sync.mjs push # Add alongside the job that runs your tests, where the report file is: # # scenario-book-results: # extends: .scenario-book-base # stage: .post # when: always # a failing test run is the one you most want in Jira # variables: # SB_LABEL: gitlab # script: # - node scenario-book-sync.mjs results reports/cucumber.json