简体   繁体   English

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

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

I want to use one gitlab-runner to make two similar, but not exact same builds. 我想使用一个gitlab-runner来制作两个相似但不完全相同的构建版本。

In the git repository, I have several branches: prod, test, dev. git存储库中,我有几个分支:prod,test,dev。 Is it possible to use only one runner to build on different paths? 是否可以只使用一个跑步者来构建不同的路径?

For example: 例如:

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

If so, how do you do that? 如果是这样,你怎么做?

Yes, you can do that. 是的,你可以这样做。

You can use this logic: 你可以使用这个逻辑:

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

You can also use when to run a job when another succeeds or fails. when另一个成功或失败when ,您还可以使用when运行作业。

Examples: 例子:

Docs: 文档:

  • GitLab CI (jobs, stages, artifacts, only & except, etc) GitLab CI (工作,阶段,工件,仅限和除外等)

Hope to have helped! 希望有所帮助!

Yes this is the default behavior. 是的,这是默认行为。 Whenever you push to the repo (regardless of the branch), an active runner will go ahead and run your build. 无论何时推送到repo(无论分支),活动的跑步者都会继续运行你的构建。 Log and artifacts are stored independently. 日志和工件独立存储。

In your .gitlab-ci.yml you can take different actions based on the branch or tag name. 在.gitlab-ci.yml中,您可以根据分支或标记名称执行不同的操作。 See http://doc.gitlab.com/ce/ci/yaml/README.html for more info and look for the only and except key words. 有关详细信息,请参阅http://doc.gitlab.com/ce/ci/yaml/README.html并查找唯一和除关键字。

Finally you can create triggers that use the API. 最后,您可以创建使用API​​的触发器。 See http://doc.gitlab.com/ce/ci/triggers/README.html 请参见http://doc.gitlab.com/ce/ci/triggers/README.html

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

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