I want to run automatically my deploy job on Gitlab when my branch receives a merge by merge request. How can I do this?
deploy-tests:
tags:
- aws-sdk
stage: deploy
only:
- stage
cache: {}
script:
- cd ngapp
- call npm ci
- call npm run-script i18n
- call npm run-script lint
- call build.bat tests
- copy .htaccess dist
- copy Web.config dist
- deploy.bat tests
If you want your pipeline to be executed when it receives an MR.
You need to pass the keyword merge_requests at your only clause. (https://docs.gitlab.com/ee/ci/yaml/#onlyrefs--exceptrefs)
Change
deploy-tests:
tags:
- aws-sdk
stage: deploy
only:
- stage
cache: {}
script:
- cd ngapp
...
To
deploy-tests:
tags:
- aws-sdk
stage: deploy
only:
- merge_requests
- stage
cache: {}
script:
- cd ngapp
...
Related
Currently I have this script in my .gitlab-ci.yml file:
image: node:16
cache:
paths:
- .npm
- cache/Cypress
- node_modules
stages:
- build
- deploy
- test
install:dependencies:
stage: build
script:
- yarn install
artifacts:
paths:
- node_modules/
only:
- merge_requests
test:unit:
stage: test
script: yarn test --ci --coverage
needs: ["install:dependencies"]
artifacts:
when: always
paths:
- coverage
expire_in: 30 days
only:
- merge_requests
deploy-to-vercel:
stage: deploy
image: node:16
script:
- npm i -g vercel
- DEPLOYMENT_URL=$(vercel -t $VERCEL_TOKEN --confirm)
- echo $DEPLOYMENT_URL > vercel_deployment_url.txt
- cat vercel_deployment_url.txt
artifacts:
when: on_success
paths:
- vercel_deployment_url.txt
only:
- merge_requests
I need to trigger a pipeline to an environment called playground but only when a pipeline from test enviroment is finished, when a pipeline to master happens, I don't to mirror to the playground environment.
Everything is deployed to vercel, and the project is powered by Next JS.
I want to enable a stage to be run during only merge_requests. But if I add only - merge_requests then the stages above such as build and test stage doesn't show up during the merge request build.
As you can see in this screenshot, the build and test stage are missing during merge_requests and only the stage deploy review is showing.
Any idea why Build and Test stage doesn't show during merge?
Here is the full cicd pipeline:
image: node
stages:
- build
- test
- deploy review
- deploy staging
- deploy production
- production tests
build website:
stage: build
script:
- sed -i "s/%%VERSION%%/$CI_COMMIT_SHORT_SHA/g" ./public/index.html
artifacts:
paths:
- ./public
test website:
stage: test
script:
- curl "http://localhost:9000" | tac | tac | grep -q "Gatsby"
deploy review:
stage: deploy review
only:
- merge_requests # The build and test stage should still be visible but it isn't
environment:
name: review/$CI_COMMIT_REF_NAME
url: http://test.surge.sh
on_stop: stop review
script:
- npm install -g surge
- surge --project ./public --domain test.surge.sh
How to build specific dist folder by specific branch in GitLab CI/CD ?
I got a main project that includes two folders,I want to build the project if I change the specific folder,such as when I changed code in Web1 folder ,then the CI/CD will be triggered and only build Web1 folder,not build all folders in the same time?
stages:
- build
build:
stage: build
tags:
- test
only:
- test
script:
# - Web1
- cd Web1
- npm install
- npm run build
- rm - rf /home/user/test/web1
- cp - r../dist/web1 /home/user/test/web1
- cd..
# - Web2
- cd Web2
- npm install
- npm run build
- rm - rf /home/user/test/web2
- cp - r../dist/web2 /home/user/test/web2
- cd..
You should create two different jobs for this, which are triggered differently with the help of the keyword changes.
One job should be triggered when changes are made in the "Web1" folder
build_web1:
stage: build
only:
changes:
- Web1/**/*
script:
- ...
and the other when changes are made in the "Web2" folder
build_web2:
stage: build
only:
changes:
- Web2/**/*
script:
- ...
I have a simple project .gitlab-ci.yaml
variables:
GIT_STRATEGY: clone
stages:
- build
build-and-run-tests:
stage: build
tags:
- windows
script:
- call npm install
- call npm run build-client-in-target
- call npm run run-tests-on-target
when I start the build pipeline, it fails while executing build-client-in-target, but the pipeline continues with success status
you should move all preprocessing to before_script tag
and remove the call command
https://docs.gitlab.com/ee/ci/yaml/#before_script-and-after_script
variables:
GIT_STRATEGY: clone
stages:
- build
build-and-run-tests:
stage: build
tags:
- windows
before_script:
- npm install
- npm run build-client-in-target
script:
- npm run run-tests-on-targe
I'm trying to setup GitLab CI for a mono repository.
For the sake of the argument, lets say I want to process 2 JavaScript packages:
app
cli
I have defined 3 stages:
install
test
build
deploy
Because I'm reusing the files from previous steps, I use the GitLab cache.
My configuration looks like this:
stages:
- install
- test
- build
- deploy
install_app:
stage: install
image: node:8.9
cache:
policy: push
paths:
- app/node_modules
script:
- cd app
- npm install
install_cli:
stage: install
image: node:8.9
cache:
policy: push
paths:
- cli/node_modules
script:
- cd cli
- npm install
test_app:
image: node:8.9
cache:
policy: pull
paths:
- app/node_modules
script:
- cd app
- npm test
test_cli:
image: node:8.9
cache:
policy: pull
paths:
- cli/node_modules
script:
- cd cli
- npm test
build_app:
stage: build
image: node:8.9
cache:
paths:
- app/node_modules
- app/build
script:
- cd app
- npm run build
deploy_app:
stage: deploy
image: registry.gitlab.com/my/gcloud/image
only:
- master
environment:
name: staging
url: https://example.com
cache:
policy: pull
paths:
- app/build
script:
- gcloud app deploy app/build/app.yaml
--verbosity info
--version master
--promote
--stop-previous-version
--quiet
--project "$GOOGLE_CLOUD_PROJECT"
The problem is in the test stage. Most of the time the test_app job fails, because the app/node_modules directory is missing. Sometimes a retry works, but mostly not.
Also, I would like to use two caches for the build_app job. I want to pull app/node_modules and push app/build. I can't find a way to accomplish this. This makes me feel like I don't fully understand how the cache works.
Why are my cache files gone? Do I misunderstand how GitLab CI cache works?
The cache is provided on a best-effort basis, so don't expect that the cache will be always present.
If you have hard dependencies between jobs, use artifacts and dependencies.
Anyway, if it is just for node_modules, I suggest you to install it in every step, instead of using artifacts - you will not save much time with artifacts.