I am using gitlab CICD to run the pipelines. In order to analyse the code with sonarqube I am using .gitlab-ci.yml file with all config as below,
stages:
- analysis
sonarqube:
stage: analysis
image: ciricihq/gitlab-sonar-scanner
variables:
SONAR_URL: https://playground.altimetrik.com/sonarqube
SONAR_ANALYSIS_MODE: issues
script:
- gitlab-sonar-scanner
I have also added sonar-project.properties
I am always ending up with error saying,
Running with gitlab-runner 11.3.1 (0aa5179e)
on Gitlab-Pipeline 04bdd119
Using Shell executor...
Running on ip-10-101-102-187.ec2.internal...
Fetching changes...
HEAD is now at 39bbd50 Update .gitlab-ci.yml
From https://gitlab.altimetrik.com/playground/node_js_usecasepg-ta1811536129881158
39bbd50..99600f7 master -> origin/master
Checking out 99600f70 as master...
Skipping Git submodules setup
$ gitlab-sonar-scanner
bash: line 57: gitlab-sonar-scanner: command not found
ERROR: Job failed: exit status 1
The same config wa working few days back, I am facing this error only in recent days. Can anyone help on this?
Thanks you...
It Seems like the sonar-scanner has not been installed in your runner.
Please verify your runner to check this.
Reference : installation steps
Related
I have a repository with one submodule. The CI is configured to clone the submodule:
variables:
GIT_STRATEGY: clone
GIT_SUBMODULE_STRATEGY: normal
I then created two jobs. One job to build on debian and one job build on windows. The debian build job works fine the submodule is cloned and the correct commit is checked out.
build:debian:
image: debian
stage: build
tags:
- linux
- docker
script:
- qmake project.pro
- make
But the windows job fails during cloning the submodule:
build:windows:
image: windows
stage: build
tags:
- windows
- docker
script:
- qmake.exe project.pro -spec win32-msvc "CONFIG+=release" -r
- nmake clean
- jom.exe -j4
The error looks like this:
Cloning into 'C:/builds/group_name/project_name/submodule_name'...
fatal: Invalid path 'C:/builds/group_name/project_name/.git/modules/submodule_name': Not a directory
fatal: clone of 'https://gitlab-ci-token:[MASKED]#gitlab.domain.com/group_name/submodule_name.git' into submodule path 'C:/builds/group_name/project_name/submodule_name' failed
Failed to clone 'submodule_name' a second time, aborting
I did not posted the first try since it is the same error message.
Do someone know this error, has a solution or maybe an idea how to fix or how to debug?
right now I'm trying to learn CI/CD with Gradle. I'm using GitLab CI's pipeline. With a Gitlab documentation and a little bit search found gilab-ci.yml like this
image: gradle:jdk11
before_script:
- export GRADLE_USER_HOME='pwd'/.gradle
cache:
paths:
- .gradle/wrapper
- .gradle/caches
package:
stage: build
script:
- ./gradlew assemble
test:
stage: test
script:
- ./gradlew check
However its not working for my Spring boot application
Gitlab pipline gives me "FATAL: file does not exist" error. I'm thinking its due to caching but everything seems okay in YAML file
Even though "FATAL: file does not exist" is red and bold, it is not failing the build but is just a warning. The actual cause of the failure is a couple of lines below: /bin/bash: line 104: ./gradlew: Permission denied.
To resolve the issue, update the build stage with the following code segment:
package:
stage: build
script:
- chmod +x ./gradlew
- ./gradlew --build-cache assemble
I have written this yml file for GitLab CI/CD. There is a shared runner configured and running.
I am doing this first time and not sure where I am going wrong. The angular js project I am having
on the repo has a gulp build file and works perfectly on local machine. This code just has to trigger
that on the vm where my runner is present. On commit the pipeline does not show any job. Let me know what needs to be corrected!
image: docker:latest
cache:
paths:
- node_modules/
deploy_stage:
stage: build
only:
- master
environment: stage
script:
- rmdir -rf "build"
- mkdir "build"
- cd "build"
- git init
- git clone "my url"
- cd "path of cloned repository"
- gulp build
What branch are you commiting to? You pipeline is configured to run only for commit on master branch.
...
only:
- master
...
If you want to have triggered jobs for other branches as well then remove this restriction from .gitlab-ci.yml file.
Do not forget to Enable shared Runners (they may not be enabled by default), setting can be found on GitLab project page under Settings -> CI/CD -> Runners.
Update: Did your pipeline triggers ever work for your project?
If not then I would try configuring simple pipeline just to test if triggers work fine:
test_simple_job:
script:
- echo I should execute for any pipeline trigger.
I solved the problem by renaming the .gitlab-ci.yaml to .gitlab-ci.yml
I just wanted to add that I ran into a similar issue. I was committing my code and I was not seeing the pipeline trigger at all.There was also no error statement on gitlab nor in my vscode. It had ran perfectly before.My problem was because I had made some recent edits to my yaml that were invalid.I reverted the changes to a known valid yaml code, and it worked again and passed.
I also had this issue. I thought I would document the cause, in the hopes it may help someone (although this is not strictly an answer for the original question because my deploy script is more complex).
So in my case, the reason was that I had multiple jobs with the same job ID in my .gitlab-ci.yml. The latter one basically rendered the earlier one invisible.
# This job will never run:
deploy_my_stuff:
script:
- do something for job one
# This job overwrites the above.
deploy_my_stuff:
script:
- do something for job two
Totally obvious... after I discovered the mistake.
I'm trying to call shell command in .gitlab-ci.yml, whose relevant parts are:
image: docker:latest
services:
- docker:dind
stages:
- build
- deploy
...
build:
stage: build
script:
- apt-get update -y
- GIT_TAG=$(git tag | tail -1)
- GIT_TAG=$(/usr/bin/git tag | tail -1)
- docker ...
However all top three shell command callings have failed, all with "command not found" error. The git command being failing is really odd, because it has to get the git repo first before start the script section. I.e., I can see that git is working, but I just can't use it myself.
Is there any way to make it working?
You see git working in separate steps because GitLab is probably doing it in another container. They keep your container clean, so you have to install dependencies yourself.
Since the image you're using is based on Alpine Linux, the command to install git is:
apk add --no-cache git
You can also skip the whole thing and use the predefined environment variables if all you need is git information. $CI_COMMIT_TAG will contain the tag and $CI_COMMIT_SHA will contain the commit hash.
from the documentation of GitLab, here is the definition of CI_COMMIT_TAG: CI_COMMIT_TAG - The commit tag name. Present only when building tags
means - when you will push a commit to GitLab, then it will start a pipeline without CI_COMMIT_TAG variable. When you make a tag on this commit and push this tag to GitLab, then another pipeline (this time for the tag, not for the commit) will be started. In that case CI_COMMIT_TAG will be present.
#xpt - thanks for the vote confidence and asking to write up this as an answer, hope this helps the community!
Maven is well installed on my gitlab-runner server. When executing mvn clean directly on my repo it works, when running my pipeline using Gitlab UI got this error :
bash: line 60: mvn: command not found
ERROR: Job failed: exit status 1
I notice that I tried to fix the problem by adding the before_script section in the .gitlab-ci.yml file :
before_script:
- export MAVEN_HOME=/usr/local/apache-maven
I add also the line :
environment = ["MAVEN_HOME=/usr/local/apache-maven"]
on the config.toml file.
the problem still persist, my executor is : shell.
Any advice!
I managed to fix the problem using this workaround:
script:
- $MAVEN_HOME/bin/mvn clean
Just add the maven docker image, add below line as first line:
image: maven:latest or image: maven:3-jdk-10 or image: maven:3-jdk-9
refer: https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/
For anyone experiencing similar issues, it might be a good idea to restart the gitlab runner ".\gitlab-runner.exe restart". Especially after fiddling with environmental variables.
There is an easier way:
Making changes in ~/.bash_profile not ~/.bashrc.
According to this document:
.bashrc it is more common to use a non-login shell
This document saying:
For certain executors, the runner passes the --login flag as shown above, which also loads the shell profile.
So it should not be ~/.bashrc, you can also try ~/.profile which It can hold the same configurations, which are then also accessible by other shells
In my scenario I do following things:
1. Set gitlab-runner's user password.
passwd gitlab-runner
2. Login gitlab-runner.
su - gitlab-runner
3. Make changes in .bash_profile
Add maven to PATH:
$ export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.9
$ export M2=$M2_HOME/bin
$ export PATH=$M2:$PATH
You can include these commands in $HOME/.bashrc
I hope you had figure out your question. I met the same question when I build my ci on my server.
I use the shell as the executer for my Runner.
here are the steps to figure out.
1 check the user on the runner server
if you had install maven on the runner server successfully, maybe it just successful for the root, u can check the real user for the ci process.
job1:
stage: test
script: whoami
if my case, it print gitlab-runner, not the root
2 su the real user, check mvn again
In this time, it print error as same as the Gitlab ci UI.
3 install maven for the real user. run the pipeline again.
You can also use as per below in the .gitlab-ci.yml
before_script:
- export PATH=$PATH:/opt/apache-maven-3.8.1/bin