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

时间:2016-03-10 11:28:00

标签: git gitlab gitlab-ci gitlab-ci-runner

我想使用一个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

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

2 个答案:

答案 0 :(得分: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(工作,阶段,工件,仅限&amp;除外等)

希望有所帮助!

答案 1 :(得分:1)

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

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

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