6

I have a server pointed as ab12.xy24.com in which the projects are placed as:

 Path-1  
 /home/ab12/public_html/project1/*  
 /home/ab12/public_html/project2/*  
 ................................
 /home/ab12/public_html/projectn/{project-files}

I am using gitlab-runner for CI and CD. The build is being built as:

 Path-2  
 /home/ab12/build/{runner-token}/{commit-id}/{group-name}/project1/{project-files}
 /home/ab12/build/{runner-token}/{commit-id}/{group-name}/project1/{project-files}

I want the build path to be as in Path-1 style instead of path-2 style.


What have I tried?

I tried changing the build_path="path1" variable which only changed:

/home/ab12/build/{runner-token}/{commit-id}/{group name}/project1/{project-files}

to

/home/ab12/path1/{runner-token}/{commit-id}/{group-name}/project1/{project-files}

I cannot also use docker as due to its virtualization concept and takes much space, which is not desired.

1
  • As far as I know you can't (to avoid race conditions between 2 builds). But if you're sure of uniqueness of builds, a symlink from path1 to path2 in the before section should do no?
    – Tensibai
    May 6, 2017 at 16:40

1 Answer 1

10

Conceptually, this approach is not the way to go; the build directory is not a deployment directory, it's a temporary directory, to build or to deploy from, whereas on a shell executor this could be fixed.

So what you need is to deploy from that directory with a script as per gitlab-ci.yml below, to the correct directory of deployment.

stages:
- deploy

variables:
  TARGET_DIR: /home/ab12/public_html/$CI_PROJECT_NAME

deploy:
  stage: deploy
  script:
     mkdir -pv $TARGET_DIR
     rsync -r --delete ./ $TARGET_DIR
  tags:
    - myrunner

This will move your projectfiles in /home/ab12/public_html/

naming your projects as project1 .. projectn, all your projects could use this same .gitlab-ci.yml file.

3
  • can you please explain its working for files handled with .gitignore... How would '''rsync help this''' Nov 24, 2017 at 5:53
  • @Wildfire not sure if I understand the question. .gitignore is used for your local tree, meaning items in .gitignore are not committed ( git commit ), thus also not pushed to the git repository and thus also not present in the CI_PROJECT_DIR. Nov 25, 2017 at 4:54
  • I am quite sure you know my question. my last comment has just my illusion... thanks Nov 27, 2017 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.