Gitlab: Pipeline Issue - gitlab

I had made a commit in the GitLab branch, then merged it into the main branch, but the .gitlab-ci.yml pipeline is not updating the last committed code into the production server.
Note: Pipeline is working, but committed changes are not visible.

Depend on your version of GitLab, it could be an older bug.
For instance, gitlab-org/gitlab-runner issue 4587 "GitlabRunner does not check out the latest commit but the previous one"
In your gitlab-ci.yml, check what
Workaround:
have same problem, but if use checkout & pull - everything ok
git checkout -f $CI_COMMIT_REF_NAME && git pull
As in, for instance:
script:
- echo $CI_COMMIT_REF_NAME
- git checkout $CI_COMMIT_REF_NAME
- git pull

I had the same issue.
Try turning off the cache in your pipeline and see once
- cache:

Related

How to fix gitLab pipeline failure

so I have been trying to push some commits to the GitLab origin, but for some reason, the pipeline is keep failing. Here is the picture.
enter image description here
I created a different branch named scrolling-logo and tried to merge it with the master branch on GitLab using git push origin, but somehow the pipeline is keep showing errors.
I tried git pull to update the master branch to its latest version on my local machine and then again tried to push to the GitLab, but it is still not working.
Does anyone know why this problem occurs?
As noted in a similar issue, make sure your GitLab pipeline does install and use the hugo_extended image, as in pages/hugo .gitlab-ci.yml.
image: registry.gitlab.com/pages/hugo/hugo_extended:latest
# Set this if you intend to use Git submodules
variables:
GIT_SUBMODULE_STRATEGY: recursive
HUGO_ENV: production
default:
before_script:
- apk add --update --no-cache git go
- git submodule update --init --recursive
- hugo mod init gitlab.com/pages/hugo
- hugo mod get -u github.com/theNewDynamic/gohugo-theme-ananke
test:
script:
- hugo
rules:
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
pages:
script:
- hugo
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
That could be enough to avoid this error.
The OP Chin-Erdene Gantulga adds in the comments:
There was this image conflict within the docker so I changed manually the image in the .gitlab-ci.yml from "latest" version to "hugo:0.91.0".
Then it worked.

Gitlab CI is ignoring ci.skip

I'm trying to create a pipeline on Gitlab CI that increments the app version everytime we get a commit on master. But it is ignoring my ci.skip command and I don't know why.
The yaml file is this one:
.gitlab-ci.yml
workflow:
rules:
- if: $CI_COMMIT_BRANCH == 'master'
before_script:
- git config --global user.email "${GITLAB_USER_EMAIL}"
- git config --global user.name "${GITLAB_USER_NAME}"
- git remote set-url origin https://push:$PUSH_KEY#$CI_SERVER_HOST/$CI_PROJECT_PATH.git
auto_release:
image: node:10
script:
- yarn
- yarn release
- git push --follow-tags origin HEAD:master -o ci.skip
- echo "Done!"
So everytime I push a new commit it gets locked inside an eternal loop that commits a new version and commits a new version over and over again. The only way to stop is manually cancelling the jobs.
Pleas note: When we use the image node or node:latest it works, but our version requires node:10 otherwise it will break and won't build.
node:10 is a very old image. The git version it contains does not support push options (at least with the shorthand -o), so that's why the push triggers the next CI build.
Check the git version in the image - if it's 2.10 to 2.17 you can use --push-option=ci.skip. If it's still an older version, you need to create your own docker image that contains node version 10 and a modern git version.

Already up to date gitlab pipeline stackoverflow

i trying gitlab pipeline. now i make some changes & code pushed in master branch
pipeline showing already update to date but i have changes in code
I try to pull in three phase but still same issue
.gitlab-ci.yml
before_script:
- echo "Before script"
building:
stage: build
script:
- git pull origin master
testing:
stage: test
script:
- git pull origin master
deploying:
stage: deploy
script:
- git pull origin master
If the gitlab-ci workflow starts by cloning your repository, no amount of git pull will change the fact you already have the full history, and, at the time of the workflow, this is "already up to date".
In other words, a git pull would not be needed in your gitlab-ci.yml file.
If your pipeline is running on the same repo that you changed, there is no need to use git pull. Although, if your pipeline triggers (on repo A) another pipeline on another repository (repo B), to access files in repo A, you have to pull repo A in repo B pipeline.

GitLab CI, monorepo and feature branch

I have a monorepo in GitLab with a Feature Branch approach.
What I'm trying to achieve is to launch the part of the pipeline associated to the directory containing the altered files. So my .gitlab-ci.yml looks like :
job1:
stage: build
script:
- ...
only:
changes:
- myparentdir/dir1/*
job2:
stage: build
script:
- ...
only:
changes:
- myparentdir/dir2/*
Create a new branch from develop
Commit myparentdir/dir2/test.txt on this branch
The pipeline launch every build jobs !
It seems like GitLab is considering every files as altered when working with a new feature branch.
Do you know any workaround?
Gitlab ci always treats changes for new branches as true. The reason is that they can't decide what to compare against.
what this means is that for the first pipeline of a new branch, everything will be built.
See the feature request for more details.
But, there is a fairly new feature called Pipelines for merge requests - that runs a stage on merge requests. Here is the feature request that implements changes with merge_requests. It's merged, but I'm not sure if it's already released. (the milestone is 11.9 - the next release)
In the meantime you can implement it yourself - You can add a stage that compares the changes (git diff) and decides whether to run the next stage:
.store_diff_from_main: &store_diff_from_main |
git diff --name-only origin/master...HEAD > "${DIFF_FILE}"
git diff --name-only HEAD~1 >> "${DIFF_FILE}"
.skip_stage: &skip_stage_condition |
echo Checking for changes in ${STAGE_PATHS}, changed files
# https://coderwall.com/p/gecfwa/git-diff-vs
cat .diff-from-master
# also cover merge squash cases
if ! (cat ${DIFF_FILE} | grep -E "${STAGE_PATHS}"); then
echo "Skipping stage ..."
exit 0
fi

Run gitlab-ci.yml only when merge request to master made

I am currently having my project in GitLab and Heroku. What I wanna do is as soon as I ask for merge request with my feature branch (let's call it crud-on-spaghetti), I want to automatically run the tests on this branch (npm test basically, using Mocha/Chai), and after they succeed, merge this crud-on-spaghetti with master, commit it and push it to origin/master (which is remote on GitLab) and after git push heroku master (basically, push it to the master branch in Heroku, where my app is stored). I have read several articles on GitLab CI and I think this is more suitable for me (rather than Heroku CI, because I do not have DEV and PROD instances).
So, as of now, I do this manually. And this is my .gitlab-ci.yml file now (which is not committed/pushed yet):
stages:
- test
- deploy
test_for_illegal_bugs:
stage: test
script:
- npm test
deploy_to_dev:
stage: deploy
only:
- origin master
script:
- git commit
- git push origin master
- git pull heroku master --rebase
- git push heroku master
Hence, my questions is: What do I exactly need to write in .gitlab-ci.yml in order to automate all these "manipulations" (above)?
PS. And another (theoretical) follow-up question: how is GitLab-CI Runner triggered? For instance, if I want it to trigger upon merge request with master, do I do that using only: ... in .gitlab-ci.yml?
Restrict stages to Merge Requests:
To have your test stage only being executed when a Merge Request (MR) is opened, use
only:
- merge_requests
According to the Gitlab docs, you can further restrict this to only being executed for MRs with a certain target branch, e.g. only MRs for master
only:
- merge_requests
except:
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME != "master"
This adds an exception for all target branches that are not master.
Or use rules: for that:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
Restrict stages to Branches:
As already mentioned by #marcolz, this is achieved by
only:
- master
to only execute the stage for pushes to the master branch.
Try
only:
- master
origin is just a name for a remote. master is the name of the branch.
The runner is triggered by GitLab-CI the moment that a commit is pushed to the repository, so alas not upon merge request.
You can use a trigger to trigger a pipeline and then call that trigger from a merge request event in integrations.

Resources