有可能在gitlab-ci中建立另一个分支到另一个目录吗?

Psy*_*oic 6 git gitlab gitlab-ci gitlab-ci-runner

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

如果是这样,您该怎么做?

Vir*_*ive 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
Run Code Online (Sandbox Code Playgroud)

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

例子:

文件:

  • GitLab CI(作业,阶段,工件,仅&除外等)

希望能有所帮助!