I am running a simple hello world python program in gitlab ci. While running it in pipeline it throws the error python not used as the name of a cmdlet.
here is my yml file
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "push"
when: always
stages:
- Test
- Build
Test_stage:
tags:
- PC_RUNNER
stage: Test
script:
- echo "Test stage started"
- cd .\test\test
- python hello.py
and here is the error
$ cd .\test\test
$ python helloworld.py
python : The naming "python" was not used as the name of a cmdlet, function, script file, or executable
program recognized. Check the spelling of the name, or if the path is correct (if included), and
repeat the process.
In C:\WINDOWS\TEMP\build_script3952941328\script.ps1:235 characters:1
+ python helloworld.py
+~~~
+ CategoryInfo : ObjectNotFound: (python:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
But when i change the command and give the full path where my python is installed it works
script:
- echo "Test stage started"
- cd .\test\test
- C:\users\abc\python\python.exe hello.py
I have added the environmental paths correctly as i have already double checked it. From the Gitlab documentation i came to know that we can also add environment variable in gitlab runner TOML file which i did as follows
executor = "shell"
shell = "powershell"
environment = ["ENV=C:\users\abc\python\", "LC_ALL=en_US.UTF-8"]
But the gitlab pipeline still throws the above error. Does someone knows what am i doing wrong here? Thanks in advance
Related
I enable CI/CD in gitlab.
I would like to, in the build job, compile a setup made with inno setup. This is yaml gitlab configuration related to build job:
build:
stage: build
script:
- echo building project...
- C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild /target:Build /property:config=Release /verbosity:q Project1.dproj /p:DCC_BuildAllUnits=true /p:"Platform=Win32"
- iscc "path/file.iss"
artifacts:
name: "test"
paths:
- Win32\Release\Project1.exe
But, when i execute the pipeline I got this error:
ISCC : Termine 'ISCC' non riconosciuto come nome di cmdlet, funzione, programma eseguibile o file script. Controllare
l'ortografia del nome o verificare che il percorso sia incluso e corretto, quindi riprovare.
I launch this pipeline in my windows machine and I already add environment variables in the system.
Anyone has idea why is wrong?
Thanks in advance
You probably need to specify the full path to your InnoSetup installation folder, or add the folder to the PATH in System Environment variables.
I've got some trouble defining a job. I'm in an early stage of defining my pipeline and I'm trying to solve my problems with variables :). I've got a few subfolder under in gcp/live/development and I'm trying to cd them and then run terraform stuff:
.plan-development:
variables:
ENVIRONMENT: "development"
TERRAFORM_DEVELOPMENT_PATH: "gcp/live/development"
TF_ROOT: ${TERRAFORM_DEVELOPMENT_PATH}/${CI_JOB_NAME%-plan-development}
stage: plan-development
script:
- cd ${TF_ROOT}
- gitlab-terraform plan
- gitlab-terraform plan-json
artifacts:
name: plan-${ENVIRONMENT}-${CI_JOB_NAME%-plan-development}
paths:
- ${TF_ROOT}/plan.cache
reports:
terraform: ${TF_ROOT}/plan.json
But according to my failing pipeline, the first script part cd ${TF_ROOT} doesn't enter the expected folder at gcp/live/development/cloud-nat.
I've got some debug outout, which tells me following:
$ cd ${TF_ROOT}
$ pwd && ls
/builds/b79ya_1j/0/devops/terraform/gcp/live/development
cloud-nat
firewall
gke
vpc
$ echo "${CI_JOB_NAME%-plan-development}"
cloud-nat
Am I missing something combing two variables (TF_ROOT: ${TERRAFORM_DEVELOPMENT_PATH}/${CI_JOB_NAME%-plan-development})?
Hope you can help me out.
Am I missing something combing two variables (TF_ROOT:
${TERRAFORM_DEVELOPMENT_PATH}/${CI_JOB_NAME%-plan-development})?
The issue is that Gitlab in variables section, doesn't perform bash operations, like you attempt here
${CI_JOB_NAME%-plan-development}
Gitlab literally searches for the variable named CI_JOB_NAME%-plan-development
That's why when it creates the TF_ROOT variable its value is gcp/live/development/ since it could not find the variable named CI_JOB_NAME%-plan-development
image: python:3.7.3
pipelines:
branches:
Server:
- step:
name: Test
script:
- echo $MYTEST
My pipeline shows this:
echo $MYTEST
+ echo $MYTEST
$MYTEST
The variable is a "Repository variable" and is named MYTEST
I have done the same process with a node image and it is working fine. Because this is a python project i took python, but the environment variables don't seem to work.
I suppose, i cannot use a pure python docker image, if i need some bash commands, correct?
My goal is to show badges (ex : ) based on pipeline results.
I have a private gitlab ce omnibus instance with the following .gitlab-ci.yml :
image: python:3.6
stages:
- lint
- test
before_script:
- python -V
- pip install pipenv
- pipenv install --dev
lint:
stage: lint
script:
- pipenv run pylint --output-format=text --load-plugins pylint_django project/ | tee pylint.txt
- score=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' pylint.txt)
- echo "Pylint score was $score"
- ls
- pwd
- pipenv run anybadge --value=$score --file=pylint.svg pylint
artifacts:
paths:
- pylint.svg
test:
stage: test
script:
- pipenv run python manage.py test
So I thought that I would store the image in the artifacts of the lint job and display it via the badge feature.
But I encounter the following issue : when I browse https://example.com/[group]/[project]/-/jobs/[ID]/artifacts/file/pylint.svg, instead of seeing the badge I have the following message :
The image could not be displayed because it is stored as a job artifact. You can download it instead.
And anyways, I feel like this is the wrong way, because even if I could get the image, there don't seems to be a way to get the image from the last job since gitlab URL for badges images only supports %{project_path}, %{project_id}, %{default_branch}, %{commit_sha}
So how one would add badge to a gitlab project based on a svg generated from results in a gitlab pipeline ?
My guess is that I could push to a .badge folder but that doesn't sound like a clean solution.
You can indeed get the artifact(s) for the latest job (see documentation here), but the trick is that you need to use a slightly different URL:
https://example.com/[group]/[project]/-/jobs/artifacts/[ref]/raw/pylint.svg?job=lint
where [ref] is the reference to your branch/commit/tag.
Speaking of badge placeholders available in Gitlab, you can potentially put %{default_branch} or %{commit_sha} into [ref]. This won't allow you to get the correct badge for every branch, but at least your default branch will get one.
Please also note that ?job=lint query parameter is required, without it the URL won't work.
GitLab-CI executes the stop-environment script in dynamic environments after the branch has been deleted. This effectively forces you to put all the teardown logic into the .gitlab-ci.yml instead of a script that .gitlab-ci.yml just calls.
Does anyone know a workaround for this? I have a shell script that removes the deployment. This script is part of the repository and can also be called locally (i.e. not onli in an CI environment). I want GitLab-CI to call this script when removing a dynamic environment but it's obviously not there anymore when the branch has been deleted. I also cannot put this script to the artifacts as it is generated before the build by a configure script and contains secrets. It would be great if one could execute the teardown script before the branch is deleted.
Here's a relevant excerpt from the .gitlab-ci.yml
deploy_dynamic_staging:
stage: deploy
variables:
SERVICE_NAME: foo-service-$CI_BUILD_REF_SLUG
script:
- ./configure
- make deploy.staging
environment:
name: staging/$CI_BUILD_REF_SLUG
on_stop: stop_dynamic_staging
except:
- master
stop_dynamic_staging:
stage: deploy
variables:
GIT_STRATEGY: none
script:
- make teardown # <- this fails
when: manual
environment:
name: staging/$CI_BUILD_REF_SLUG
action: stop
Probably not ideal, but you can curl the script using the gitlab API before running it:
curl \
-X GET https://gitlab.example. com/raw/master/script.sh\
-H 'PRIVATE-TOKEN: ${GITLAB_TOKEN}' > script.sh
GitLab-CI executes the stop-environment script in dynamic environments after the branch has been deleted.
That includes:
An on_stop action, if defined, is executed.
With GitLab 15.1 (June 2022), you can skip that on_top action:
Force stop an environment
In 15.1, we added a force option to the stop environment API call.
This allows you to delete an active environment without running the specified on_stop jobs in cases where running these defined actions is not desired.
See Documentation and Issue.