Reputation: 31
I have a Gitlab CI pipeline with Powershell script. The pipeline is executed scuccessfully but didn't get any result. The purpose of Pipeline is to create a checkpoint on PTC Windchill server. The pipeline doesn't create a checkpoint.
However when I run the same script on same Gitlab runner agent windows powershell. It is working fine. I don't know whats happens wrong with Gitlab pipeline. The same script also working perfect in Jenkins pipeline.
In the pipeline scritp I am making a connection with PTC Windchill server. Its working when I run the script directly on powershell but not working in Gitlab pipeline.
.gitlab-ci.yml
build-job:
stage: build
script:
- '"C:\Program Files (x86)\Integrity\ILMClient11\bin\mksAPIViewer.exe" --iplocal --xml si checkpoint --hostname=test --port=7001 --label="TA/test" --project=test'
Pipeline Logs
Running with gitlab-runner 15.0.0 (febb2a09)
on Scriptrunner-Shared-Q BcVqDFkp
Resolving secrets
00:00
Preparing the "shell" executor
00:00
Using Shell executor...
Preparing environment
00:00
Running on DEGTSECE092...
Getting source from Git repository
00:01
Fetching changes with git depth set to 20...
Reinitialized existing Git repository in C:/DevApps/GitLabRunner/builds/BcVqDFkp/0/dvcs/defurq/sandbox/.git/
Checking out 54d3bf5a as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:01
$ echo "just for teting"
just for teting
$ (dir 2>&1 *`|echo CMD);&<# rem #>echo PowerShell
PowerShell
$ Start-Process "C:\Program Files (x86)\Integrity\ILMClient11\bin\mksAPIViewer.exe" -ArgumentList "--iplocal --xml si checkpoint --hostname=mks.de.miele.net --port=7001 --label=TA/test --project=/Playground/EC_Spielwiese/Furqan_project/project.pj" >C:\Users\yygte56\Desktop\test\cmdtest.txt
Cleaning up project directory and file based variables
00:00
Job succeeded
Upvotes: 3
Views: 1174
Reputation: 1168
It seems like the pipeline is executing the command correctly, but the result is not being captured. The pipeline logs only show the output of the command if it is being captured to the console or a file. It looks like the pipeline is capturing the output of the command by writing it to a file
C:\Users\yygte56\Desktop\test\cmdtest.txt.
However, the output of the file is not shown in the pipeline logs. If you want to capture the output of the command in the pipeline logs, you can modify the script to include the output of the file in the pipeline logs. For example:
build-job:
stage: build
script:
- $result = Start-Process "C:\Program Files (x86)\Integrity\ILMClient11\bin\mksAPIViewer.exe" -ArgumentList "--iplocal --xml si checkpoint --hostname=mks.de.miele.net --port=7001 --label=TA/test --project=/Playground/EC_Spielwiese/Furqan_project/project.pj" -PassThru
- $result.ExitCode
- cat C:\Users\yygte56\Desktop\test\cmdtest.txt
This will capture the exit code of the command and the contents of the output file in the pipeline logs.
Upvotes: 1
Reputation: 114461
There are a couple of things.
start-process
without -wait
will run in parallel and your pipeline will continue. If this is one of the last tasks, gitlab will likely kill it as part of cleaning up child processes of the workflow.-argumentlist
expects an array of arguments, but you pass them as a single big string. With quotes in it. This will mess things up.start-process
you need to add: -NoNewWindow -PassThru | out-file test.txt
start-process
at all.First, try calling the executable directly and capturing the output:
$output = & "C:\Program Files (x86)\Integrity\ILMClient11\bin\mksAPIViewer.exe" --iplocal --xml si checkpoint --hostname=test --port=7001 --label="TA/test" --project=test
$output | out-file text.txt
Alternatively, try:
start-process "C:\Program Files (x86)\Integrity\ILMClient11\bin\mksAPIViewer.exe" -wait `
-argumentlist @("--iplocal", "--xml", "si", "checkpoint", "--hostname=test", "--port=7001" "--label=TA/test", "--project=test") `
-NoNewWindow -PassThru` | out-file test.txt
Upvotes: 1