是否可以在 gitlab-ci 中建立另一个分支到另一个目录?

Is it possible in gitlab-ci build another branch to another directory?

我想用一个 gitlab-runner 来制作两个相似但不完全相同的作品。

git 存储库中,我有几个分支:prod、test、dev。 是否可以只使用一个跑步者在不同的路径上建造?

例如:

如果是,你是怎么做到的?

是的,这是默认行为。每当您推送到回购协议(无论分支如何)时,活跃的 运行ner 将继续并 运行 您的构建。日志和工件独立存储。

在您的 .gitlab-ci.yml 中,您 可以 根据分支或标签名称采取不同的操作。有关详细信息,请参阅 http://doc.gitlab.com/ce/ci/yaml/README.html 并查找唯一和除外关键字。

最后,您可以创建使用 API 的触发器。参见 http://doc.gitlab.com/ce/ci/triggers/README.html

是的,你可以做到。

你可以使用这个逻辑:

image: <image>       # choose your image (ryby, python, node, php etc)

# add cache for speeding up builds
cache:
  paths: 
    - <cache-folder>/ # the name will need to be set according to your project

before_script:
  - <your command>    # here you set the commands you want to run for every commit 
  - <your command>

# add a job called 'build' -> to run your builds
build:
  stage: build        # this will define the stage
  script:
    - <your scripts>  # choose the script you want to run first
  only:
    - build           # the 'build' job will affect only 'build' branch

# add a job called 'test' -> to run your tests
test:
  stage: test         # this will define the stage
  script:
    - <your scripts>  # choose the script similar to the deployment
  except:
    - master          # the 'test' job will affect all branches expect 'master'

# the 'deploy' job will deploy and build your project
deploy:
  stage: deploy
  script:
    - <your scripts>  # your deployment script
  artifacts:
    paths:
      - <folder>      # generate files resulting from your builds for you to download 
  only:
    - master          # this job will affect only the 'master' branch

您还可以使用 when 来 运行 一个作业 when 另一个成功或失败。

示例:

文档:

  • GitLab CI(工作、阶段、工件、唯一和除外等)

希望对您有所帮助!