如何将CI/CD Gitlab管道中的工作延迟到一定时间?

发布于 2025-02-11 07:14:17 字数 389 浏览 1 评论 0 原文

使用 start_in:30分钟可以延迟作业(例如,提交后的实时部署)。

htttps:// docs。 gitlab.com/ee/ci/jobs/job_control.html#run-a-job-ab-after-a-delay

问题:是否也可以创建延迟直到特定时间?

例如,部署被推迟到5A.M.吗? 类似 start_at:05:00 之类的东西?

With start_in: 30 minutes it's possible to delay a job (eg live deployment after a commit).

https://docs.gitlab.com/ee/ci/jobs/job_control.html#run-a-job-after-a-delay

Question: is it possible to also create a delay until a specific time?

Eg that the deployment is delayed until 5a.m.?
Something like start_at: 05:00?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还如梦归 2025-02-18 07:14:17

您可以用a 。生成配置的作业可以计算当前时间和所需部署时间之间的时间,并将其嵌入到 start_in 参数的生成的配置中。

例如:

create_deploy_pipeline:
  stage: build
  script:
  # modify this line or write a script that suits your needs
  # here, we calculate the number of seconds between now and "5AM tomorrow"
  - seconds_until_deploy=$(( $(date +%s -d "tomorrow 05:00") - $( date +%s ) ))
  - |
    cat > dynamic.yml << EOF
    deploy_job:
      script:
        - ./deploy.sh
      when: delayed
      start_in: ${seconds_until_deploy} seconds
    EOF
artifacts:
    paths:
      - dynamic.yml


deploy-pipeline:
  stage: test
  trigger:
    include:
      - artifact: dynamic.yml
        job: create_deploy_pipeline

请记住,您需要考虑跑步者使用的时区(或使用UTC时间计算)以获得准确的计算。

You could approximate this with a dynamic child pipeline. The job that generates the configuration can calculate how much time is inbetween the current time and the desired deploy time and embed that in the generated config for the start_in parameter.

As an example:

create_deploy_pipeline:
  stage: build
  script:
  # modify this line or write a script that suits your needs
  # here, we calculate the number of seconds between now and "5AM tomorrow"
  - seconds_until_deploy=$(( $(date +%s -d "tomorrow 05:00") - $( date +%s ) ))
  - |
    cat > dynamic.yml << EOF
    deploy_job:
      script:
        - ./deploy.sh
      when: delayed
      start_in: ${seconds_until_deploy} seconds
    EOF
artifacts:
    paths:
      - dynamic.yml


deploy-pipeline:
  stage: test
  trigger:
    include:
      - artifact: dynamic.yml
        job: create_deploy_pipeline

Keep in mind that you will need to consider the timezone used by your runner (or calculate using UTC time) to get an accurate calculation.

岁月染过的梦 2025-02-18 07:14:17

您可能正在寻找的是 this

编辑:避免重复管道运行已记录在在这里。如果您标记部署,则可以构建这样的命令:

git log --oneline $(git describe --tags --abbrev=0 @^)..@

这将告诉您自上次标签以来是否有任何提交。这可能是要弄清楚的工作控制功能,是否再次运行。

What you are probably looking for is a scheduled pipeline. Scheduled pipelines benefit from execution based on cron clauses. You can limit the execution of your complete pipeline definition on a step by step basis like this.

EDIT: Avoiding duplicate pipeline runs has been documented here. If you tag your deployments you could build a command like this:

git log --oneline $(git describe --tags --abbrev=0 @^)..@

This will tell you if there are any commits since the last tag. This could be a Job Control feature to figure out, whether to run again or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文