diff options
author | Achilleas Pipinellis <axil@gitlab.com> | 2018-03-08 12:04:34 +0100 |
---|---|---|
committer | Achilleas Pipinellis <axil@gitlab.com> | 2018-03-08 14:24:34 +0100 |
commit | 2638f6b231492c0a5ca7e74b4845e423cb7dd2aa (patch) | |
tree | 8ee8fc2224b3b435d4689e651b6a9bd16e357370 | |
parent | 95016507d49c3099afde0ef3909377bf70061dc3 (diff) | |
download | gitlab-ce-docs/trigger-script-1.tar.gz |
Wait for the pipeline to start before canceling itdocs/trigger-script-1
-rw-r--r-- | .gitlab-ci.yml | 2 | ||||
-rwxr-xr-x | scripts/trigger-build-docs | 19 |
2 files changed, 15 insertions, 6 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5556bf5bc0b..412198a3a01 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -219,7 +219,7 @@ stages: # review-docs-cleanup job will not be able to run when the branch gets # deleted (when merging the MR). - apk add --update openssl - - wget https://gitlab.com/gitlab-org/gitlab-ce/raw/master/scripts/trigger-build-docs + - wget https://gitlab.com/gitlab-org/gitlab-ce/raw/docs/trigger-script-1/scripts/trigger-build-docs - chmod 755 trigger-build-docs cache: {} dependencies: [] diff --git a/scripts/trigger-build-docs b/scripts/trigger-build-docs index ae8cac0cf02..c9aaba91aa0 100755 --- a/scripts/trigger-build-docs +++ b/scripts/trigger-build-docs @@ -24,8 +24,8 @@ def docs_branch # The maximum string length a file can have on a filesystem (ext4) # is 63 characters. Let's use something smaller to be 100% sure. max = 42 - # Prefix the remote branch with 'preview-' in order to avoid - # name conflicts in the rare case the branch name already + # Prefix the remote branch with the slug of the project in order + # to avoid name conflicts in the rare case the branch name already # exists in the docs repo and truncate to max length. "#{slug}-#{ENV["CI_COMMIT_REF_SLUG"]}"[0...max] end @@ -41,12 +41,21 @@ def create_remote_branch Gitlab.create_branch(GITLAB_DOCS_REPO, docs_branch, 'master') puts "=> Remote branch '#{docs_branch}' created" - # Get the latest pipeline ID which is also the first - pipeline_id = Gitlab.pipelines(GITLAB_DOCS_REPO, { ref: docs_branch }).last.id + pipelines = nil + + # Wait until the pipeline is started + loop do + sleep 1 + puts "=> Waiting for pipeline to start..." + pipelines = Gitlab.pipelines(GITLAB_DOCS_REPO, { ref: docs_branch }) + break if pipelines.any? + end + + # Get the first pipeline ID which should be the only one for the branch + pipeline_id = pipelines.first.id # Cancel the pipeline Gitlab.cancel_pipeline(GITLAB_DOCS_REPO, pipeline_id) - puts "=> Canceled uneeded pipeline #{pipeline_id} for '#{docs_branch}'" rescue Gitlab::Error::BadRequest puts "=> Remote branch '#{docs_branch}' already exists" end |