In my .gitlab-ci.yml, I want to separate my cmake pre-build job and my build job.
For this, I tried to use cache but it seems that my pre-build folder is not passed to my build job.
Here is my .gitlab-ci.yml:
image: ubuntu:22.04
before_script:
- apt update
- apt install cmake ninja-build gcc-arm-none-eabi -y
stages:
- build
pre-build:
stage: build
script:
- cmake --preset=Release
cache:
paths:
- build/Release
policy: push
build:
stage: build
script:
- cmake --build build/Release
cache:
paths:
- build/V2_Release
policy: pull
I found the answer:
image: ubuntu:22.04
before_script:
- apt update
- apt install cmake ninja-build gcc-arm-none-eabi -y
stages:
- pre-build
- build
pre-build:
stage: pre-build
script:
- cmake --preset=Release
artifacts:
paths:
- build/V2_Release
expire_in: 5 mins
build:
stage: build
script:
- cmake --build build/Release
artifacts:
paths:
- build/Release/main.bin
Related
I have multiple manual jobs, where only one needs to be selected. Once one is selected I want to disable the other jobs. In this example I have 3 npm jobs, once the dev chooses one of these, I want to disable the other two jobs from being able to run. I was going to add a needs dependency but that only allows you to select a job that has already run.
Here is what I have so far:
publish_patch:
stage: deploy
image: node:latest
before_script:
- cp $SCRT_NPMRC_TOKEN .npmrc
script:
- npm version patch
- npm publish
- git checkout main
- git add package.json package-lock.json
- git commit -m "automatic version commit"
- git push -o ci.skip
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH
when: manual
publish_minor:
stage: deploy
image: node:latest
before_script:
- cp $SCRT_NPMRC_TOKEN .npmrc
script:
- npm version minor
- npm publish
- git checkout main
- git add package.json package-lock.json
- git commit -m "automatic version commit"
- git push -o ci.skip
when: manual
publish_major:
stage: deploy
image: node:latest
before_script:
- cp $SCRT_NPMRC_TOKEN .npmrc
script:
- npm version patch
- npm publish
- git checkout main
- git add package.json package-lock.json
- git commit -m "automatic version commit"
- git push -o ci.skip
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH
when: manual
I have this .gitlab-ci.yml file:
image: node:latest
stages:
- build
- test
- publish
cache:
key:
files:
- package.json
- package-lock.json
paths:
- node_modules
build:
stage: build
script:
- echo -e "//my.private.repo.com/:_authToken=${NPM_TOKEN}\n$(cat .npmrc)">.npmrc
- npm install
- npm run build
artifacts:
paths:
- node_modules
- .npmrc
test:
stage: test
script:
- npm test
publish:
stage: publish
script:
- npm publish
only:
- tags
With this configuration, when I push a simple commit, everything is ok : build + test as expected.
But, when I push tag (created here with npm version, two pipeline are created : 1 for the commit, and 1 for the tag. So, build and tests are executed twice.
What can I do to prevent this behavior, and have the tag pipeline to "cancel" the commit pipeline
You could have different jobs for when you push a simple commit or tag, and use only and except keywords to differentiate between the cases, otherwise this is the correct behaviour considered by GitLab. You can see the discussion around a closed issue here.
I have a simple .gitlab-ci.yml file that builds my Vue application. I build once and then deploy the dist folder to my various environments:
stages:
- build
- deploy_dev
- deploy_stg
- deploy_prd
build:
image: node:latest # Pull Node image
stage: build
script:
- npm install -g #vue/cli#latest
- npm install
- npm run build
artifacts:
expire_in: 2 weeks
paths:
- dist/
deploy_to_dev:
image: python:latest
stage: deploy_dev
dependencies:
- build
only:
- master # Only deply master branch automatically to Dev
script:
- export AWS_ACCESS_KEY_ID=$DEV_AWS_ACCESS_ID
- export AWS_SECRET_ACCESS_KEY=$DEV_AWS_ACCESS_KEY
- pip install awscli # Install AWS CLI
- aws s3 sync ./dist s3://$DEV_BUCKET
This all works great, however, I've now introduced some config and build my app differently per environment - for 3 environments I have 3 different build commands. Eg, I have an .env.production so for a production build my command becomes:
npm run build -- --mode production
Is there any way to get around having different builds for each environment but still using the .env files based on a GitLab variable?
You should split your build job to have one per environment and use the environment concept to have something like that for dev and production envs :
.build_template: &build_template
image: node:latest # Pull Node image
script:
- npm install -g #vue/cli#latest
- npm install
- npm run build -- --mode $CI_ENVIRONMENT_NAME
build_dev:
stage: build_dev
<<: *build_template
environment:
name: dev
build_prod:
stage: build_prod
<<: *build_template
environment:
name: production
In this snippet, I used anchors to avoid duplicate lines.
I'm looking for a solution to my problem. I want to run sequentially jobs by environment using gitlab-ci.
Build dev (manual launch) -----> create docker image dev (automatic if dev build works)
Build staging (manual launch) ------> create docker image staging (automatic if staging build works)
...
If the dev build fails, I don't want to create the docker image dev.
How can I do this ? Morever, is it possible to do a for loop to build each environment ?
Here what I currently do :
stages:
- build
- docker-image
dev:build:
stage: build
script:
- npm install
- npm run build:development
when: manual
staging:build:
stage: build
script:
- npm install
- npm run build:staging
when: manual
demo:build:
stage: build
script:
- npm install
- npm run build:demo
when: manual
dev:image:
stage: docker-image
script:
- docker build -t registry/project:dev --build-arg environment=development .
#- docker push registry/project:dev
when: on_success
staging:image:
stage: docker-image
script:
- docker build -t registry/project:staging --build-arg environment=staging .
#- docker push registry/project:staging
when: manual
demo:image:
stage: docker-image
script:
- docker build -t registry/project:demo --build-arg environment=demo .
#- docker push registry/project:demo
when: manual
Thank you very much
You should disallow failure for the manual jobs so the pipeline will not continue any further on the unsuccessful build.
Manual jobs are allowed to fail by default.
To disallow failure:
dev:build:
stage: build
script:
- npm install
- npm run build:development
when: manual
allow_failure: false
Note:
when: on_success
on your dev:image job is either wrong syntax or does nothing.
I've added a config.yml file to a react-native project in the .circleci/ directory in order to configure a build pipeline.
But in my CircleCI 2.0 server only the first job, build runs while test and android don't run although they are part of the overall workflow config.
I've followed the workflow configuration guide here https://circleci.com/docs/2.0/workflows/ to configure a sequential workflow.
I did verify that my CI server is using the config below
Question:
How do you configure a sequential workflow on CircleCI 2.0?
config.yml file in repo:
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2
machine:
environment:
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
dependencies:
override:
- yarn
- jest
cache_directories:
- ~/.cache/yarn
- ~/.cache/jest
build:
override:
- yarn install
jobs:
build:
working_directory: ~/repo
docker:
- image: circleci/node:8
steps:
- checkout
- run: yarn install
- persist_to_workspace:
root: ~/repo
paths:
- node_modules
test:
working_directory: ~/repo
docker:
- image: circleci/node:8.9.0
steps:
- checkout
- run: yarn install
- run: npm test
- persist_to_workspace:
root: ~/repo
paths:
- node_modules
android:
working_directory: ~/repo/android
docker:
- image: circleci/android:api-27-node8-alpha
steps:
- checkout:
path: ~/repo
- attach_workspace:
at: ~/repo
- run: bundle install
#- run: bundle exec fastlane test
- store_test_results:
path: ~/root/android/reports
workflows:
version: 2
node-android:
jobs:
- build:
filters:
tags:
ignore: /^testing
- test
requires:
- test
- android:
requires:
- test
- build
I fixed the workflow by removing the CI 1.0 syntax as #FelicianoTech mentioend, this piece of YAML is not 2.0 CircleCI syntax:
machine:
environment:
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
dependencies:
override:
- yarn
- jest
cache_directories:
- ~/.cache/yarn
- ~/.cache/jest
build:
override:
- yarn install