6

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

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

例如:

  • /home/gitlab-runner/builds/860ee11a/0/projectname- 产品
  • /home/gitlab-runner/builds/860ee11a/1/projectname- 测试
  • /home/gitlab-runner/builds/860ee11a/2/projectname- 开发

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

4

2 回答 2

5

是的,你可以这么做。

您可以使用以下逻辑:

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(工作、阶段、工件、仅和除外等)

希望有所帮助!

于 2016-03-11T04:10:27.750 回答
1

是的,这是默认行为。每当您推送到存储库(无论分支如何)时,一个活跃的运行器都会继续运行您的构建。日志和工件是独立存储的。

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

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

于 2016-03-10T12:26:23.793 回答