[英]Disallow CI pipelines of one GitLab project to run concurrently?
在一台內部 GitLab 服務器上,有一個項目的 CI 腳本不允許同時執行多個管道(Kube.netes 中的外部副作用)。 因此,如果連續推送兩個提交,其間的時間少於第一個管道需要完成的時間,則兩個管道將同時運行,這會導致兩者都失敗。
在這種情況下,為 CI runner(一個 K8s runner 在多個 repos 中使用)全局設置concurrent = 1
是不可行的,因為應該允許使用該 runner 的其他項目的管道同時運行。
是否可以僅針對一個項目禁止 CI 並發? 取消舊管道或排隊新管道都可以。
您可以按照以下鏈接中的討論使用limit =1
https://gitlab.com/gitlab-org/gitlab-ce/issues/18224
concurrent = 3 // Attribute that limits a number of projects
check_interval = 0
[[runners]]
limit = 1 // Attribute that limits quantity job by runners
name = "test-ci"
url = "https://gitlab.com/ci"
token = "38274bf1655a0f48d72b15815a83d4e6a85689"
executor = "shell"
[runners.cache]
[[runners]]
limit = 1
name = "teste2"
url = "https://gitlab.com/ci"
token = "38274bf1655a0f48d72b15815a83d4e6a85689"
executor = "shell"
[runners.cache]
不要使用共享的運行器,而是在您的案例中使用項目特定的運行器,這樣其他項目就不會受到影響
您現在可以使用資源組來防止作業同時運行。 請在此處查看 2020 年的介紹文檔。
為確保作業在任何給定時間只運行一次(即防止並發運行),您可以使用一些唯一名稱將resource_group
鍵添加到您的作業中:
deploy:
stage: deploy
script: echo "Your deployment script"
resource_group: production
此外,您可以設置資源組的“進程模式”來指定作業運行的順序。 oldest_first
是更明顯的一個,作業將按照創建它們的順序運行。
首次創建后,您需要使用 API 更新資源組的進程模式。 例如:
curl --location --request PUT 'https://gitlab.com/api/v4/projects/:project_id/resource_groups/production' \
--header 'Authorization: Bearer <your token>' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'process_mode=oldest_first'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.