简体   繁体   English

在 gitlab-runner docker exec 中运行默认 before_script

[英]Running default before_script in gitlab-runner docker exec

I have a gitlab ci configuration that I want to run locally.我有一个想要在本地运行的 gitlab ci 配置。 I can see that I can do that using gitlab-runner docker exec in this answer: Use GitLab CI to run tests locally?我可以看到我可以在这个答案中使用gitlab-runner docker exec来做到这一点: 使用 GitLab CI 在本地运行测试? . . However, my gitlab configuration uses a default before_script, and when I run a job with gitlab-runner docker exec <job-id> , the default before_script doesn't get run.但是,我的 gitlab 配置使用默认的 before_script,当我使用gitlab-runner docker exec <job-id>运行作业时,默认的 before_script 不会运行。

Here is an example configuration that demonstrates the issue这是一个演示该问题的示例配置

image: openjdk:8

default:
  before_script:
    - echo TEST1
    - echo TEST1
    - echo TEST1
    - echo TEST1

test:
  script:
    - echo TEST3

I can get default before_script to run in the gitlab pipeline, just not locally.我可以让默认 before_script 在 gitlab 管道中运行,而不是在本地运行。 If I run gitlab-runner exec docker test with this configuration, only the TEST3 gets printed.如果我使用此配置运行gitlab-runner exec docker test ,则仅打印 TEST3。 How can I get the default before_script to run?如何让默认的 before_script 运行?

It seems that the default: yml keyword is not currently supported by the gitlab-runner exec command: https://docs.gitlab.com/runner/commands/#limitations-of-gitlab-runner-exec . gitlab-runner exec命令当前不支持default: yml 关键字: https://docs.gitlab.com/runner/commands/#limitations-of-gitlab-runner-exec So there appears to be no way to do what I am trying to do.所以似乎没有办法做我想做的事情。

There is apparently plans by Gitlab to fix this: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2797 , but no timeline given for when/if this will be delivered. Gitlab 显然计划解决此问题: https://gitlab.com/gitlab-org/gitlab-runner/-/issues/2797 ,但没有给出何时/是否交付的时间表。

image: openjdk:8

stages:
  - default
  - test

default:
  before_script:
    - echo TEST1
    - echo TEST1
    - echo TEST1
    - echo TEST1

test:
  script:
    - echo TEST3

or或者

before_script:
    - echo TEST1
    - echo TEST1
    - echo TEST1
    - echo TEST1

test:
  script:
    - echo TEST3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM