So I have many many small projects on gitlab, all use the same CI script to build. To make entire system cleaner I put the CI script in its own project and the small projects CI script just pull the script from the central project i.e.
stages:
- build
include:
- project: 'Company/CI-Templates'
file: '/Swift-Apple/Swift_Apple_Build.yml'
With the central script being like
stages:
- build
before_script:
- git submodule sync --recursive
- git submodule update --init --recursive
build_project:
stage: build
script:
- xcodebuild archive -scheme "$AppName" -archivePath "build/App.xcarchive"
- xcodebuild -exportArchive -archivePath "build/App.xcarchive" -exportPath "build/" -exportOptionsPlist "ExportOptions.plist"
- appcenter login --token $AppCenterToken
- appcenter distribute release -f "$IPAPath" -g Collaborators -r "$Reason" --app $AppCenterPath
Now this runs as expected, the central script when called runs local in the project. The issue I have is "ExportOptions.plist" is a separate file that ideally id like to be in the central CI location, but as the script runs local when called, im unsure what file path to put in.
Could you download "ExportOptions.plist" from your central CI project with curl? Then you can load it locally.
Related
I have a project in gitlab and want to deploy this to a specific directory on a Linux server using the .gitlab-ci.yml for which I am facing an issue.
I have setup a gitlab runner for "cms-project" and added .gitlab-ci.yml to the root directory
When I push to the repository, the runner fetches the commits to the following directory
home/gitlab-runner/builds/ziwwUK3Jz/0/project/cms_project
Now I want the runner to fetch the commit to the dev server which is located in
/var/www/project-cms.com/html
I have tried the changes and below is the .gitlab-ci.yml file
job_main:
type: deploy
script: cd /var/www/project-cms.com/html && git pull
deploy:
stage: deploy
only:
- master
variables:
BRANCH: master
script:
- composer install
but I am getting the following error
Removing modules/contrib/
Removing vendor/
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ cd /var/www/project-cms.com/html && git pull
error: cannot open .git/FETCH_HEAD: Permission denied
The user has the root permissions to the directory.
I have already gone through this link "https://stackoverflow.com/questions/37564681/gitlab-ci-how-to-deploy-the-latest-to-a-specific-directory" but that did not help
can anyone please help me to deploy the project to the "/var/www/project-cms.com/html" directory?
It is because you did not understand the difference between the gitlab-runner and your server
This code is running inside a "machine" called gitlab runner that is responsible to execute anything that you want. But it is not your web server.
To be able to deploy your code, you need to build a script that will run inside this runner and you need to understand that your entire code is inside this runner (this is the reason that you found your code inside the /builds folder.
So you need to tell to your runner to copy your code to your webserver, using any protocol/binary like ssh, ftp, sftp etc.
Edit: If your runner is running inside your webserver, you just need to copy the code to your folder, do not need to pull with git anymore
Some examples here: https://docs.gitlab.com/ee/ci/examples/
Docs: https://docs.gitlab.com/ee/ci/
Runner docs: https://docs.gitlab.com/runner/
I've been trying to setup a CI/CD Pipeline on my Repo which runs common tasks like linting/tests etc. I've successfully setup a Gitlab-Runner which is working fine. The only part I'm stuck is the "deploy" part.
When I run my build, how do I actually get the files into my /var/www/xyz folder.
I get that everything is running in a Docker Container and I can't just magically copy paste my files there, but i don't get how I get the files on my actual server-directory. I've been searching for days for good docs / explanations, so as always, StackOverflow is my last resort for help.
I'm running on a Ubuntu 20.04 LTS VPS and a SaaS GitLab-Repository if that info is needed. That's my .gitlab-ci.yml:
image: timbru31/node-alpine-git
before_script:
- git fetch origin
stages:
- setup
- test
- build
- deploy
#All Setup Jobs
Install Dependencies:
stage: setup
interruptible: true
script:
- npm install
- npm i -g #nrwl/cli
artifacts:
paths:
- node_modules/
# All Test Jobs
Lint:
stage: test
script: npx nx run nx-fun:lint
Tests:
stage: test
script: npx nx run nx-fun:test
Deploy:
stage: build
script:
- ls /var/www/
- npx nx build --prod --output-path=dist/
- cp -r dist/* /var/www/html/neostax/
only:
refs:
- master
Normally I would ssh into my server, run the build, and then copy the build to the corresponding web-directory.
TL;DR - How do I get files from a GitLab-Runner to an actual directory on the server?
i go a CICD that make an artifact and save them in public folder
i need to copy some files of these artifacts to another project
what script i can't use or what the best way to do it?
Assuming, you want to copy file into another gitlab project.
Once artifact is built in a job, in a stage (ie : build), it will be available in all jobs of the next stage (ie : deploy).
build-artifact:
stage: build
script:
- echo "build artifact"
artifacts:
name: "public"
paths:
- "public/"
deploy_artifact:
stage: deploy
script:
- cd public/ # here are your artifact files.
- ls -l
- cd ..
# now implement copy strategy,
# for example in a git repo :
- git clone https://myusername:mypassord#myrepo.gitlab.com/mygroup/another_project.git
- cd another_project
- cp ../public/source_file ./target_file
- git add target_file
- git commit -m "added generated file"
- git push
If your destination is not a git repository, you can simply replace by a scp directly to server, or any other copy strategy, directly in the script.
Another way to do it is to get the last artifact of project A, inside the ci of Project B.
Please see https://docs.gitlab.com/ee/ci/pipelines/job_artifacts.html#retrieve-job-artifacts-for-other-projects
When you do trigger to downstream pipelines, just use needs from job that push artifacts, then it will be passed to downstream.
During deployment using gitlab runner it checkouts out the codebase including the .git folder, I presume this is the default behaviour?
Without manually cleaning the .git folder in our deployment script, is there an option to use git archive instead?
eg.
deploy-dev:
when: manual
stage: deploy
script:
- bash deploy.sh $CI_COMMIT_REF_SLUG $CI_BUILD_TOKEN
include-git: false
I have tried searching on google but couldn't find any relevant results (maybe due to bad search keywords)
I have a remote server where I serve my project via Nginx. I am using Gitlab CI to automatize my deploy process and I have ran into a problem. When I push my commits to the master branch the gitlab-runner run nicely but the problem is that it removes my React build folder (it is ok, as I have put it into the .gitignore), but because it always removes my build folder my Nginx could not serve any files until the build finish, and a new build folder creaeted. Is is there any solution for this problem? It would be nice if I could cache my build file until the build process finish. I attached my gitlab.ci.yml. Thank's in advance!
image: docker:latest
services:
- docker:dind
stages:
- build
- deploy
variables:
GIT_SSL_NO_VERIFY: "1"
build-step:
stage: build
tags:
- shell
script:
- docker image prune -f
- docker-compose -f docker-compose.yml -f docker-compose.prod.yml build
deploy-step:
stage: deploy
tags:
- shell
script:
- docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
It should be possible to use git fetch and to disable git clean when your deploy job starts. Here are links for the variables to do this:
https://docs.gitlab.com/ee/ci/yaml/#git-clean-flags
https://docs.gitlab.com/ee/ci/yaml/#git-strategy
It would look something like this:
deploy-step:
variables:
GIT_STRATEGY: fetch
GIT_CLEAN_FLAGS: none
stage: deploy
tags:
- shell
script:
- docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d
This should make GitLab use git fetch instead of git clone, and to not run any git clean ... commands. The build artifacts from your previous run should then not be removed.
There are some problems with this though. If something goes wrong with a build, you might end up in a situation where you will have to manually log into the server where the runner is to fix it. The reason that GitLab uses git clean is to prevent these types of problems.
A more proper solution is to use nginx to have a sort of dubble buffer. You can have two different build folders, change the config in nginx, and then send a signal to nginx to reload the config. nginx will then make sure to gracefully switch to the new version of your application, without any interruptions. Here is a link to someone that has done this:
https://syshero.org/2016-06-09-zero-downtime-deployments-using-nginx/