Gitlab CloudFormation Integration Pipeline - gitlab

Description: Attempting to create a simple pipeline to create a cloudformation stack in an aws account.
Looks like its failing to find a script referenced in the documentation below, but I thought cloudformation cli commands were now supported in gitlab 13.9?
Gitlab Version:13.9
CI/CD variables setup:
See required ones here.
https://docs.gitlab.com/ee/ci/cloud_deployment/
gitlab yaml file
variables:
REGION: us-east-2
CI_AWS_CF_STACK_NAME: 'gitlabTestStack'
CI_AWS_CF_CREATE_STACK_FILE: 'aws/aws-test-stack.yaml'
deploy:
stage: deploy
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
script:
- gl-cloudprovision create-stack
Output
on PDOCK009-Runner-TestAutomation6 UrKKxyCW
Preparing the "docker" executor
Using Docker executor with image registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest ...
Pulling docker image registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest ...
Using docker image sha256:a39347bds862894f38dabf38f1fddfa0avbc1dc3070ca12400fd0a8d33e7178 for registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest ...
Preparing environment
Running on runner-urkkxycw-project-1427-concurrent-0 via 9cdf65ce059d...
Getting source from Git repository
00:01
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/jackoneill/aws-deploy/.git/
Created fresh repository.
From <URL>
* [new ref] fbf7a9b966f0be1e2db8fbf7a983c02c90ed8saxc2323x -> refs/pipelines/65421
* [new branch] master -> origin/master
Checking out fbf7a9 master...
Skipping Git submodules setup
Restoring cache
Downloading artifacts
00:02
Running before_script and script
00:02
$ gl-cloudprovision create-stack
/usr/bin/bash: line 103: gl-cloudprovision: command not found
Running after_script
Uploading artifacts for failed job
00:02
ERROR: Job failed: exit code 1

Looks like you need to change image to
image: 'registry.gitlab.com/gitlab-org/cloud-deploy/aws-cloudformation:latest'
and script from
- gl-cloudprovision create-stack
to
- gl-cloudformation create-stack

Related

Gitlab-ci stage image not pulled

I'm facing an strange behaviour.
Below my .gitlab-ci.yml
image: node:latest
stages:
- release
release:
image: registry.gitlab.com/gitlab-org/release-cli
stage: release
script:
- release-cli create --name release-branch-$CI_JOB_ID --description "desc" --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA
The pipeline is finishing with the following error:
Running with gitlab-runner 14.6.0 (5316d4ac)
on shell-runner gmyChsa1
Preparing the "shell" executor
Using Shell executor...
Preparing environment
Running on myserver.com...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/gmyChsa1/0/kleyson-sr/changelog-test/.git/
Checking out 21ab4cac as main...
Removing desc.md
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ release-cli create --name release-branch-$CI_JOB_ID --description "desc" --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA
bash: line 137: release-cli: command not found
Cleaning up project directory and file based variables
ERROR: Job failed: exit status 1
The stage release is not pulling and using the release-cli image instead of the global node:latest image.
How can I fix that ?
PS.: Running the pipeline in a local gitlab server.
Running with gitlab-runner 14.6.0 (5316d4ac)
on shell-runner gmyChsa1
Your job is using a GitLab runner configured with the shell executor. This means that the image: directive is ignored entirely.
To use an image: you will need to use a runner configured with a docker/kubernetes/custom executor that supports running jobs in an image.

GitLab CI Timeout with Kaniko and EKS

I am trying to follow the GitLab example code for using kaniko as outlined here. The only thing I have changed is that I am using the v1.7.0-debug tag instead of simply debug.
build:
stage: build
image:
name: gcr.io/kaniko-project/executor:v1.7.0-debug
entrypoint: [""]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"${CI_REGISTRY}\":{\"auth\":\"$(printf "%s:%s" "${CI_REGISTRY_USER}" "${CI_REGISTRY_PASSWORD}" | base64 | tr -d '\n')\"}}}" > /kaniko/.docker/config.json
- >-
/kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}"
My build job is stalling out at the following line:
Running with gitlab-runner 14.4.0 (4b9e985a)
on gitlab-runner-gitlab-runner-84d476ff5c-mkt4s HMty8QBu
Preparing the "kubernetes" executor
00:00
Using Kubernetes namespace: gitlab-runner
Using Kubernetes executor with image gcr.io/kaniko-project/executor:v1.7.0-debug ...
Using attach strategy to execute scripts...
Preparing environment
00:03
Waiting for pod gitlab-runner/runner-hmty8qbu-project-31186441-concurrent-0bbt8x to be running, status is Pending
Running on runner-hmty8qbu-project-31186441-concurrent-0bbt8x via gitlab-runner-gitlab-runner-84d476ff5c-mkt4s...
Getting source from Git repository
00:01
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/...
Created fresh repository.
Checking out 4d05d22b as ci...
Skipping Git submodules setup
Executing "step_script" stage of the job script
It just stops at Executing "step_script" and never moves on. I've researched all over and read through as much documentation as I can find but am unable to troubleshoot this issue.
Setup
Amazon EKS version 1.21
GitLab Runner Helm Chart version 0.34.0
kaniko executor image v1.7.0-debug
This ended up being an issue with how the Kubernetes runner itself was configured inside of the runner configuration toml. The default container image we were using for our runners required a modification to the PATH environment variable so we were using the environment configuration setting to do this as outlined here. It seems that this PATH variable did not include the busybox shell defined in the kaniko debug image. We have since moved that PATH change inside our Docker image where it should've been in the first place and things are working as expected.

GitLab pipeline throwing an error "Error: Could not find or load main class"

While trying to run the GitLab pipeline, I am getting an error
"Error: Could not find or load main class Testing\GitLab-Runner\builds\EgKZ847y\0\sandeshmms\LearningSelenium..m2.repository"
Also, it is giving this message:
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Below is the console message:
Running with gitlab-runner 14.2.0 (58ba2b95)
on my-runner1 EgKZ847y
Preparing the "shell" executor 00:00
Using Shell executor...
Preparing environment
Running on HOMEPC...
Getting source from Git repository 00:10
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in D:/Java Testing/GitLab-Runner/builds/EgKZ847y/0/sandeshmms/LearningSelenium/.git/
Checking out 41ee697d as develop...
git-lfs/2.12.1 (GitHub; windows 386; go 1.14.10; git 85b28e06)
Skipping Git submodules setup
Restoring cache 00:02
Version: 14.2.0
Git revision: 58ba2b95
Git branch: 14-2-stable
GO version: go1.13.8
Built: 2021-08-22T19:47:56+0000
OS/Arch: windows/386
Checking cache for default-14...
Runtime platform arch=386 os=windows pid=5420 revision=58ba2b95 version=14.2.0
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted.
Successfully extracted cache
Executing "step_script" stage of the job script 00:03
$ echo "Testing Job Triggered"
Testing Job Triggered
$ echo $CI_PROJECT_DIR
D:\Java Testing\GitLab-Runner\builds\EgKZ847y\0\sandeshmms\LearningSelenium
$ mvn $MAVEN_OPTS clean test
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Error: Could not find or load main class Testing\GitLab-Runner\builds\EgKZ847y\0\sandeshmms\LearningSelenium..m2.repository
Uploading artifacts for failed job 00:02
Version: 14.2.0
Git revision: 58ba2b95
Git branch: 14-2-stable
GO version: go1.13.8
Built: 2021-08-22T19:47:56+0000
OS/Arch: windows/386
Uploading artifacts...
Runtime platform arch=386 os=windows pid=4312 revision=58ba2b95 version=14.2.0
WARNING: target/surefire-reports/*: no matching files
ERROR: No files to upload
Cleaning up file based variables 00:01
ERROR: Job failed: exit status 1
Below is the complete yaml file:
stages:
- test
variables:
# This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
# `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
paths:
- .m2/repository
test job:
stage: test
tags:
- testing
script:
- echo "Testing Job Triggered"
- echo $CI_PROJECT_DIR
- 'mvn $MAVEN_OPTS clean test'
- echo "Testing Job Finished"
artifacts:
when: always
paths:
- target/surefire-reports/*
But if I remove the variables section and cache section from the yaml file and in the script section if I give just mvn clean test, then the build runs fine.
Also, it is downloading the maven repository to 'C:\Windows\System32\config\systemprofile\.m2\repository'. Any reason why it is downloading to this directory ?
Can anyone please help on this ?
The message No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. just means that your GitLab instance isn't configured to use a service like AWS S3 or Min.io to store your cached items. Without it, the cache can only be stored locally where your Gitlab-Runners are running. This also means that the cache stored on one runner cannot be shared with another runner, which is most likely how you can run into the error you have. You also don't have a key, so the runner doesn't know when to download which cached items.
Here's an example of a job building NPM dependencies that use the cache and a key for the specific ref name (a branch, commit, or tag):
...
Run NPM Install:
stage: build
cache:
key: $CI_COMMIT_REF_NAME
paths:
- node_modules
script:
- npm ci
artifacts:
paths:
- node_modules
...
In this job, for the first pipeline for the branch, commit, or tag under CI_COMMIT_REF_NAME, it will run npm ci and upload it as an artifact for jobs later in the pipeline to use. However, if a pipeline for the same branch, commit, or tag is run again, instead of running npm ci it will download the cached node_modules directory, and upload that as an artifact.
See Caching in GitLab CI/CD for more information on caching, and Distributed Caching for information on using S3 or Minio to distribute your cache across all runners.

GitLab CI/CD and GitLab Package Registry - change maven artifact name during deployment

I'm trying to create my first GitLab CI pipeline which will deploy Maven artifact to the GitLab Package Registry following that example.
My question is how can I change artifact name (append to it) during the deployment stage as APP_PACKAGE_SNAPSHOT which I have defined in the init stage as variable
ini:
stage: init
script:
- APP_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
- APP_PACKAGE_NAME=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout)
- APP_PACKAGE_SNAPSHOT="SNAPSHOT-$CI_COMMIT_SHORT_SHA"
when pipeline was executed from the develop branch.

how to troubleshoot the error of Job Failed in Gitlab after running the pipline

Pipline created
stages:
- test
postman_test:
stage: test
image: postman/newman_alpine33
script:
- newman --version
The Response Received
Running with gitlab-runner 13.5.0-rc2 (71c90c86) on
docker-auto-scale 72989761 Preparing the "docker+machine" executor
00:18 Using Docker executor with image postman/newman_alpine33 ...
Pulling docker image postman/newman_alpine33 ... Using docker image
sha256:5cf77cf6f69fea69952c84d804c6dee67bc7c2b66d2962769dfb99ebbd69dedb
for postman/newman_alpine33 with digest
postman/newman_alpine33#sha256:7cd459dc2e9dd8a743548c4f8080f2c38c4e7b7163a0d533ecc3c8099b93b6d9
... Preparing environment 00:04 Running on
runner-72989761-project-21805329-concurrent-0 via
runner-72989761-srm-1602779557-742dd19f... Getting source from Git
repository 00:01 $ eval "$CI_PRE_CLONE_SCRIPT" Fetching changes with
git depth set to 50... Initialized empty Git repository in
/builds/aylin2/project-test/.git/ Created fresh repository. Checking
out fb728cf0 as master... Skipping Git submodules setup Executing
"step_script" stage of the job script 00:02 error: unknown option '-c'
Cleaning up file based variables 00:00 ERROR: Job failed: exit code 1

Resources