Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

In the git repository, I have several branches: 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/1/projectname - test
  • /home/gitlab-runner/builds/860ee11a/2/projectname - dev

If so, how do you do that?

like image 698
Psychozoic Avatar asked Mar 10 '16 11:03

Psychozoic


People also ask

How does GitLab branching work?

Feature branching Git workflow Every feature gets its own branch when developers commit to this workflow. Rather than commit directly to the main branch, developers create a branch, make changes, and then merge it into main. Ideally, a branch should have a lifespan of a few hours.

Who can create a branch in GitLab?

Step 1 − Login to your GitLab account and go to your project under Projects section. Step 2 − To create a branch, click on the Branches option under the Repository section and click on the New branch button. Step 3 − In the New branch screen, enter the name for branch and click on the Create branch button.

Can I change default branch in GitLab?

Change the default branch name for a project Sign in to GitLab with at least the Maintainer role. In the left navigation menu, go to Settings > Repository. Expand Default branch, and select a new default branch.

How do you run a script from file in another project using include in GitLab-CI?

If you have access project A and B, you can use multi-project pipelines. You trigger a pipeline in project A from project B. In project A, you clone project B and run your script.


2 Answers

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.

Examples:

  • Test + Build for GitLab Pages website
  • Multiple stages for iOS app
  • PHP project with a lot of nice stuff

Docs:

  • GitLab CI (jobs, stages, artifacts, only & except, etc)

Hope to have helped!

like image 117
Virtua Creative Avatar answered Nov 15 '22 05:11

Virtua Creative


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. Log and artifacts are stored independently.

In your .gitlab-ci.yml you can take different actions based on the branch or tag name. See http://doc.gitlab.com/ce/ci/yaml/README.html for more info and look for the only and except key words.

Finally you can create triggers that use the API. See http://doc.gitlab.com/ce/ci/triggers/README.html

like image 41
Marco van Neerbos Avatar answered Nov 15 '22 05:11

Marco van Neerbos