Circle-ci: No workflow when I set filters to only tags and ignore all branches - continuous-integration

I’m trying to run a workflow only on tags, but I’m getting no workflow
And when I remove ignore branches, it runs on every branch and tag.
Do I miss something? Or what exactly can I achieve with this usecase?
This is a screenshot, and I’m expecting the workflow to run on instable-2.7.31.
Screenshot- noworkflow
Thanks.
My .circleci/config.yml
only-deploy-unstable: &only-deploy-unstable
context: Unstable-context
filters:
tags:
only: /^unstable-.*/
branches:
ignore: /.*/
version: 2.1
jobs:
build_unstable:
docker:
- image: docker:20.10.8
environment:
DOCKER_IMAGE_BASE_URL: **********
steps:
- checkout
- setup_remote_docker
- run: apk update
- run: apk add git
- run: docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- run:
name: build and push unstable docker image
no_output_timeout: 15m
command: |
export TAG_NAME=$(git describe --tags --abbrev=0)
echo ${DOCKER_IMAGE_BASE_URL}:$TAG_NAME
docker build --build-arg STAGING=test --rm -t $DOCKER_IMAGE_BASE_URL:$TAG_NAME -t $DOCKER_IMAGE_BASE_URL:latest .
docker push $DOCKER_IMAGE_BASE_URL:$TAG_NAME
docker push $DOCKER_IMAGE_BASE_URL:latest
deploy_unstable:
docker:
- image: docker:20.10.8
steps:
- checkout
- setup_remote_docker
- run: command -v ssh-agent >/dev/null || ( apk add --update openssh )
- run: eval $(ssh-agent -s)
- run: ********************
workflows:
# build unstable-version
build_and_push_unstable:
jobs:
- build_unstable: *only-deploy-unstable
- hold:
<<: *only-deploy-unstable
type: approval
requires:
- build_unstable
- deploy_unstable:
<<: *only-deploy-unstable
requires:
- hold

Could be the syntax when you reference your YAML alias. Have you tried:
- build_unstable:
<<: *only-deploy-unstable
- hold:
<<: *only-deploy-unstable
type: approval
requires:
- build_unstable
- deploy_unstable:
<<: *only-deploy-unstable
requires:
- hold

Related

Can someone advise me a good practice for my Azure DevOps deployment

Good afternoon,
I am building a CI pipeline in Azure DevOps which is new ground for me. I managed to create add the build tasks en steps that I wanted. Although there still are some issues. I explain those issues down here.
Issue #1
I misunderstood the meaning of the latest tag. I thought it would automatically pull the latest/newest version from the specified Docker Hub.
Currently my Docker build looks like this:
- task: Docker#2
displayName: 'Build Docker image'
inputs:
repository: '<my_repo_name>'
command: 'build'
Dockerfile: '**/Dockerfile'
tags: $(Build.BuildId)
This pipeline YAML is to deploy to my production VPS which I added under Pipelines -> Environments.
Here is the deployment step of the pipeline:
- deployment: VMDeploy
displayName: 'Deployment to VPS'
pool:
vmImage: 'Ubuntu-20.04'
environment:
name: CDB_VPS
resourceName: <my_resource_name>
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- script: docker pull <my_repo_name>:latest
- script: docker stop $(docker ps -aq)
- script: docker run -p 8085:8085 <my_repo_name>:latest
Issue #2
I do not get any errors in the pipeline while running it. But I am wondering if this is a good practice. By using this it will always run version latest. Also I don't think this is how I should deploy.
Issue #3
The deployment block gets executed before the build and push block is finished. To give extra information I will post the entire YAML file down here.
trigger:
- master
jobs:
- job: Build
displayName: 'Build Maven project and Docker build'
steps:
- task: replacetokens#3
displayName: 'Replace tokens'
inputs:
targetFiles: |
**/application.properties
- task: Maven#3
displayName: 'Build Maven project'
inputs:
mavenPomFile: 'pom.xml'
goals: 'package'
jdkVersionOption: 11
publishJUnitResults: true
- task: Docker#2
displayName: 'Build Docker image'
inputs:
repository: '<my_repo_name>'
command: 'build'
Dockerfile: '**/Dockerfile'
tags: $(Build.BuildId)
- task: Docker#2
displayName: 'Push Docker image to Docker hub'
inputs:
containerRegistry: 'Dockerhub connection'
repository: '<my_repo_name>'
command: 'push'
Dockerfile: '**/Dockerfile'
tags: $(Build.BuildId)
- deployment: VMDeploy
displayName: 'Deployment to VPS'
pool:
vmImage: 'Ubuntu-20.04'
environment:
name: CDB_VPS
resourceName: <my_vps_resource_name>
resourceType: VirtualMachine
strategy:
runOnce:
deploy:
steps:
- script: docker pull <my_repo_name>:latest
- script: docker stop $(docker ps -aq)
- script: docker run -p 8085:8085 <my_repo_name>:latest
If you want to make this on specific image please replace latest with $(Build.BuildId).
steps:
- script: docker pull <my_repo_name>:$(Build.BuildId)
- script: docker stop $(docker ps -aq)
- script: docker run -p 8085:8085 <my_repo_name>:$(Build.BuildId)
And if you want VMDeploy waits for Build please add dependsOn
- deployment: VMDeploy
depenedsOn: Build
Issue #1
The tag in the docker task mean: A list of tags in separate lines. These tags are used in build, push and buildAndPush commands. We could see the tag in the docker, such as below.
Issue #2
We could check the latest deploy in the docker and Azure DevOps pipeline log to ensure that it always run version latest
Issue #3
You could check Krzysztof Madej answer.

Yaml : Formatting error in yaml file. expected '<document start>', but found '<block mapping start>

version: 2.1
executors:
docker-publisher:
environment:
IMAGE_NAME: vinaya.nayak/mocking-service
docker:
- image: circleci/buildpack-deps:stretch
jobs:
build:
executor: docker-publisher
steps:
- checkout
- setup_remote_docker
- run:
name: Build Docker image
command: |
docker build -t $IMAGE_NAME:latest .
- run:
name: Archive Docker image
command: docker save -o mocking.tar $IMAGE_NAME
- persist_to_workspace:
root: .
paths:
- ./mocking.tar
publish-latest:
executor: docker-publisher
steps:
- attach_workspace:
at: /tmp/workspace
- setup_remote_docker
- run:
name: Load archived Docker image
command: docker load -i /tmp/workspace/mocking.tar
- run:
name: Publish Docker Image to Docker Hub
command: |
echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
docker push docker.kfz42.de/v2/java/mocking-service/$IMAGE_NAME:latest .
workflows:
version: 2
build-master:
jobs:
- build:
filters:
branches:
only: master
- publish-latest:
requires:
- build
filters:
branches:
only: master
can some one help me with whats wrong with my yaml file. I get the following error. I even tried using yaml formatter and the yaml formatter says that this is a valid yaml file
!/bin/sh -eo pipefail Unable to parse YAML expected '', but found '' in 'string', line 39,
column 1: workflows: Warning: This configuration was auto-generated to
show you the message above. Don't rerun this job. Rerunning will have
no effect. false Exited with code 1
Your file starts with a key-value pair indented with two spaces, so you have a root level node that is a mapping. That is fine as long as all other root level are indented two spaces as well.
workflows is not indented, that is why the parser expected a new document.
version: 2.1
executors:
docker-publisher:
environment:
IMAGE_NAME: vinaya.nayak/mocking-service
docker:
- image: circleci/buildpack-deps:stretch
jobs:
build:
executor: docker-publisher
steps:
- checkout
- setup_remote_docker
- run:
name: Build Docker image
command: |
docker build -t $IMAGE_NAME:latest .
- run:
name: Archive Docker image
command: docker save -o mocking.tar $IMAGE_NAME
- persist_to_workspace:
root: .
paths:
- ./mocking.tar
publish-latest:
executor: docker-publisher
steps:
- attach_workspace:
at: /tmp/workspace
- setup_remote_docker
- run:
name: Load archived Docker image
command: docker load -i /tmp/workspace/mocking.tar
- run:
name: Publish Docker Image to Docker Hub
command: |
echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
docker push docker.kfz42.de/v2/java/mocking-service/$IMAGE_NAME:latest .
workflows:
version: 2
build-master:
jobs:
- build:
filters:
branches:
only: master
- publish-latest:
requires:
- build
filters:
branches:
only: master
I fixed the above problem by indenting workflows with 2 spaces

Runnig tasks only when merging to master

I use the following config which works as expected, it run the command on each PR or merge to the master, Now I want to make some integration test which I want to run only when merged to the master, all the PR should remain the same (and run the following config as before). the nuance here is that for the integration test I need other docker image and different run command to execute (which should execute only when merging to the master), is it possible to do it with CircleCI ?
# Golang CircleCI 2.0 configuration file
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.11
working_directory: /go/src/sbr
steps:
- checkout
- run: go version
- run: go env
- run: go get -v -t -d ./...
- run: go test -v ./...
I try to add another docker image under the existing one but I got error
update:
version: 2
jobs:
build:
docker:
- image: circleci/golang:1.11
working_directory: /go/src/sbr
steps:
- checkout
- run: go version
- run: go env
- run: go get -v -t -d ./...
- run: go test -v ./...
test-integration:
docker:
- image: other-image
workflows:
version: 2
builds:
jobs:
- build
integration-test:
jobs:
- test-integration:
requires:
- build
filters:
branches:
only: master
The issue here that I got error when adding to the second workflow the require
requires:
- build
I want that before the test test-integration it will also run the build job as per-requiste . what im doing wrong ?
The error is:
requires job \"build\" but \"build\" is not part of this workflow.
# At least one job in the workflow must have no dependencies.
# The following jobs are unreachable: integration
#
# -------
# Don't rerun this job. Rerunning will have no effect.
false
Your configuration has a single job named build and no workflows. It sounds like what you want is to run a second job for integration tests, and to have the second job only run when the branch is master. To accomplish both of those you would use a workflow with two jobs.
See https://circleci.com/docs/2.0/configuration-reference/#workflows
An example of what that might look like:
jobs:
build:
docker:
- image: circleci/golang:1.11
...
test-integration:
docker:
- image: other-image
...
workflows:
version: 2
workflow-name:
jobs:
- build
- test-integration:
filters:
branches:
only: master

Appveyor deployment into 2 different locations based on branch commit yml parse error

I have a pretty simple scenario where I want to deploy to two different locations depending on the commit happening on dev branch or master. Since its imposible to have two different yml files on these branches since one overwrites the other every time I came about this article here:
https://www.appveyor.com/blog/2014/07/23/appveyor-yml-and-multiple-branches/
The article makes it clear we can use one yml file to set htis up howver I het an error:
Error parsing appveyor.yml: (Line: 35, Col: 1, Idx: 554) - (Line: 35, Col: 9, Idx: 562): Duplicate key
Here is my yml
image: Visual Studio 2017
environment:
nodejs_version: "6"
platform:
- x64
install:
- ps: Install-Product node $env:nodejs_version
- yarn install --no-progress
build_script:
- yarn ng -- build --prod --aot --no-progress
cache:
- node_modules -> yarn.lock
- "%LOCALAPPDATA%/Yarn"
branches:
only:
- master
artifacts:
path: '\dist\'
name: NINJASPA
before_deploy:
ssh root#ipadresshere -t "ls; rm -r -v /var/www/asp/ninjacodingfront/*; ls; exit; bash --login"
deploy:
provider: Environment
name: NinjaCodingFront
branches:
only:
- dev
artifacts:
path: '\dist\'
name: NINJASPADEV
before_deploy:
ssh root#ipadresshere -t "ls; rm -r -v /var/www/asp/ninjacodingfrontdev/*; ls; exit; bash --login"
deploy:
provider: Environment
name: NinjaCodingFrontDev
Line 35 is where branches dev comes come:
branches: --------------- (line 35)
only:
- dev
No idea what to do next, please help. Hope its solvable. Thanks!
So finally this is how its done:
image: Visual Studio 2017
platform:
- x64
environment:
nodejs_version: "6"
install:
- ps: Install-Product node $env:nodejs_version
- yarn install --no-progress
build_script:
- yarn ng -- build --prod --aot --no-progress
cache:
- node_modules -> yarn.lock
- "%LOCALAPPDATA%/Yarn"
for:
-
branches:
only:
- master
deploy:
provider: Environment
name: NinjaCodingFront
artifacts:
path: '\dist\'
name: NINJASPA
before_deploy:
ssh root#xxxxxxxxx -t "ls; rm -r -v /var/www/asp/ninjacodingfront/*; ls; exit; bash --login"
-
branches:
only:
- dev
deploy:
provider: Environment
name: NinjaCodingFrontDev
artifacts:
path: '\dist\'
name: NINJASPADEV
before_deploy:
ssh root#xxxxxxxxxxx -t "ls; rm -r -v /var/www/asp/ninjacodingfrontdev/*; ls; exit; bash --login"

unable to link gitlab services to own container in .gitlab-ci.yml

I have a simple .gitlab-ci.yml file:
image: docker:latest
services:
- docker:dind
- postgres:9.5
stages:
- build
- test
variables:
STAGING_REGISTRY: "dhub.example.com"
CONTAINER_TEST_IMAGE: ${STAGING_REGISTRY}/${CI_PROJECT_NAME}:latest
before_script:
- docker login -u gitlab-ci -p $DHUB_PASSWORD $STAGING_REGISTRY
build:
stage: build
script:
- docker build --pull -t $CONTAINER_TEST_IMAGE -f Dockerfile-dev .
- docker push $CONTAINER_TEST_IMAGE
test:
stage: test
script:
- docker run --env-file=.environment --link=postgres:db $CONTAINER_TEST_IMAGE nosetests
Everything works fine until the actual test stage. In test I'm unable to access my postgres service.
docker: Error response from daemon: Could not get container for postgres.
I tried to write test like this:
test1:
stage: test
image: $CONTAINER_TEST_IMAGE
services:
- postgres:9.5
script:
- python manage.py test
But in this case, I'm unable to pull this image, because of authentication:
ERROR: Preparation failed: unauthorized: authentication required
Am I missing something?

Resources