是否有可能在gitlab-ci中构建另一个分支到另一个目录?

问题描述 投票:5回答:2

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

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

例如:

  • /home/gitlab-runner/builds/860ee11a/0/projectname - prod
  • /home/gitlab-runner/builds/860ee11a/1/projectname - 测试
  • /home/gitlab-runner/builds/860ee11a/2/projectname - dev

如果是这样,你怎么做?

git gitlab gitlab-ci gitlab-ci-runner
2个回答
4
投票

是的,你可以这样做。

你可以使用这个逻辑:

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(工作,阶段,文物,仅限和除外等)

希望有所帮助!


1
投票

是的,这是默认行为。无论何时推送到repo(无论分支),活动的跑步者都会继续运行你的构建。日志和工件独立存储。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.