Gitlab output log display runtime values instead of variables - gitlab

Is it possible to get GitLab to report out what it's actually running in the output log. For example, the following .gitlab-ci.yml
variables:
MAVEN_CLI_OPTS: >-
-s $CI_PROJECT_DIR/.m2/settings.xml
--batch-mode
--errors
--fail-at-end
--show-version
-DinstallAtEnd=true
-DdeployAtEnd=true
compile-test-package:
stage: package
script:
- mvn ${MAVEN_CLI_OPTS} package
The run log then shows this
...
mvn ${MAVEN_CLI_OPTS} package
...
But I really would like it to give the specific details like
...
mvn -s path/to/my/project/.m2/settings.xml --batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true package
...

The best I've learned on this is that GitLab doesn't have a way to report the full details of what its executing. As Michael Delgado mentioned, putting an echo in to output will give you a method to do this. However use this with cation cause protected values could be exposed using this method.
I'm still struggling with variable replacement but at least now I can see what GitLab is replacing and not.

Related

Where on GitLab.com do I find the pipeline error logs?

I've been working on getting a .gitlab-ci.yml pipeline to work but cannot find where the logs go.
GitLab.com message tells me
npm ERR! /root/.npm/_logs/2022-05-06T09_39_43_597Z-debug.log
I do not see this folder created on my project within GitLab.com so where and how do I get to the log?
After 51 iterations I have made a little bit of progress. 1st time seeing Green.
You could use artifacts to keep the log file, if the job fails. For example:
my job:
...
artifacts:
paths:
- "*.log"
when: on_failure
I'm not sure the paths pattern is correct. So, perhaps, it is neccessary to use **/*.log instead of *.log. But I hope, the idea is clear.
That can be seen by adding debug logging to your .gitlab-ci.yml file.Once you add it ,run the job again and you can get a detailed log

What is the "release" stage in gitlab-ci good for?

Can someone explain to me in simple terms what the release stage actually does, and why that is useful?
As for as I understand the official documentation, all it does is create some kind of tag?!
EDIT: (responding to wedm)
I am referring to the stage described on the official gitlab documentation on https://docs.gitlab.com/ee/ci/yaml/#release
This page describes all the details, but I don't get the big picture: Why are we doing this, what are we trying to accomplish here?
I have taken over a project that has a "release" stage after the deploy stage:
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- build-release-env
rules:
- if: "$CI_COMMIT_TAG =~ /^v/"
variables:
ASSET_URL_BUILD: "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_SHA}/download?job=build-www"
ASSET_URL_BUNDLE: "${CI_PROJECT_URL}/-/jobs/artifacts/${CI_COMMIT_SHA}/download?job=docker-image"
script:
- echo "Creating release for ${CI_COMMIT_TAG} (${CI_COMMIT_SHA})"
- cat ./CHANGELOG.latest.md
- |
release-cli create --name "Release ${CI_COMMIT_TAG}" --tag-name ${CI_COMMIT_TAG} \
--description ./CHANGELOG.latest.md \
--assets-link "{\"name\":\"Complete Build\",\"url\":\"${ASSET_URL_BUILD}\"}" \
--assets-link "{\"name\":\"Docker image\",\"url\":\"${ASSET_URL_BUNDLE}\"}" \
--ref ${CI_COMMIT_SHA}
Quoted from the GitLab documentation about releases (emphasis mine):
To introduce a checkpoint in your source code history, you can assign a Git tag at the moment of release. However, in most cases, your users need more than just the raw source code. They need compiled objects or other assets output by your CI/CD system.
One common example would be to attach built binaries to a release.
Concerning your given example: from the script part it looks like it's creating a gitlab release for the project it's run on. Doing that programmatically gives some advantages, as not all options (e.g. timed releases) are available via the web ui of gitlab.

Gitlab runner does not always update environment

I have a gitlab job that does not seem to update the repository before being run. Sometimes it leaves some files in their old states and run the script... Any idea ?
For instance when I have a
packagePython:
stage: package
script:
- .\scripts\PackagePython.ps1
tags:
- myServer
cache:
paths:
- .\python\cache\
only:
changes:
- python/**/*
I finally managed to understand what was happening :
I realised that the gitlab-runner did not use exactly the same path for each run on my server, and my script assumed that it did... So I ended up pointing on a build made on the wrong path.
I guess if you think that it is not updating the repository (like I did) make sure you are not referencing hardcoded path/package in your scripts that could refer to previous versions !

gitlab-ci.yml cannot resolve predefined environment variables

In my .gitlab-ci.yml i'm trying to deploy on merge request.
My pipeline works, script is executed , everything is ok and running , but i'm not able to read any predefined environment variables. My files looks like :
executeAutomationTests:
stage: check
only:
refs:
- merge_requests
script:
- echo $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
But $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME is not resolved. I need to know source branch for the merge_request in order to pull the code and make a deployment. I have tried other variables like : $CI_COMMIT_REF_NAME, $CI_JOB_STAGE , but non of them are resolved.
My GitLab version : GitLab Community Edition 13.4.2
The problem was that in the pipeline job monitor the variable wasn't resolved and that's confused me. It was looking like :
So, for anyone who is fighting with such things, keep that in mind and also, keep in mind differences in syntax between powershell , bash and so on ..

Gitlab CI variables returns empty string?

It's been 2 days since one of my project' build starts failing on Gitlab CI. The main error was E_MISSING_APP_KEY and when I check another variable just by echoing $HOST and $PORT from my .gitlab-ci.yml config, like this
tests:
script:
- echo "${HOST} ${PORT}"
- node -e "console.log(process.env.HOST, process.env.PORT)"
- node_modules/.bin/nyc node ace test -t 0
I got nothing.
The build was failed because it can't read my environment variable that I set on its CI Settings.
Anyone experiencing same issue? & how to solve this?
Update:
I'm trying to create new project with only containing .gitlab-ci.yml file here and it's seems working just fine
But why the world it's still failing on my main project?
For anyone else having a similar problem:
check your variable, if it is protected your branch has to be protected as well or remove the protected option on your variable
The issue is solved by delete all of my variables I've had & set them back from the CI Setting. And the build pipeline is running without any errors. (except the actual testing is still failed, lol)
Honestly, I'm still wondering why this could happened? and hopefully no one will experiencing same kind of issue like me here..

Resources