powershell script hung while running

34 views
Skip to first unread message

Nayan Makwana

unread,
Aug 22, 2022, 8:30:13 AM8/22/22
to go-cd
Dear folks,
I just created a PowerShell script that just prints a hello msg but it hugs when I execute the job 

how to rectify the issue I am using gocd 22.2.0 Linux server and windows 10 gocd agent

Thank You
Nayan Makwana

Jason Smyth

unread,
Aug 22, 2022, 10:58:35 AM8/22/22
to go-cd
Hello Nayan,

Would you please clarify what you mean when you say "it hugs"? All of the following seem likely, and the way to resolve the issue will depend on what the actual situation is:

1. GoCD fails to schedule the job.
2. The job is scheduled as expected but is never assigned to an agent.
3. The job is assigned to an agent but the work seems to not get started.
4. The agent does some of the work but then hangs without completing.

Each of these scenarios are different, and each requires different troubleshooting steps.

Do any of them apply to you? Or does "it hugs" mean something else in this context?

Regards,
Jason Smyth

Nayan Makwana

unread,
Aug 23, 2022, 8:20:09 AM8/23/22
to go-cd
thank you for replay Jason
i resolve the issue I am truing to run powershell script like .\filename.ps1 but its hugs now I am running as powershell.exe --executionpolicy remotesigned -File file.ps1

But now the issue is I unable to access the environment variable in power shell script I tried echo and Write-OutPut but non of them print value of variable so please help me out fir the same 

Thanks and regards
Nayan Makwana

Jason Smyth

unread,
Aug 23, 2022, 8:57:18 AM8/23/22
to go-cd
Hello Nayan,

It's tough to say without seeing your code. There are multiple ways to access variables in PowerShell, depending on what you are trying to achieve.

Write-Output (or its alias, echo) takes an object and outputs it to the PowerShell pipeline. By default, the pipeline's output is sent to the terminal, so one way to print the contents of an environment variable is to use the special "env" PowerShell drive:

Write-Output -InputObject $env:COMPUTERNAME

Hope this helps.

Regards,
Jason Smyth

Nayan Makwana

unread,
Aug 23, 2022, 9:08:02 AM8/23/22
to go-cd
I trying like this 

env_val.pngpowershell.png

but non of the work for me to print the msg

Jason Smyth

unread,
Aug 23, 2022, 9:28:15 AM8/23/22
to go-cd
Hello Nayan,

Unlike Bash, PowerShell (PS) stores environment variables in a separate namespace from "regular" variables. The code sample you provided references regular variables, not environment variables.

The easiest way I know of to work with (existing) environment variables in PS is to use the "env" PS drive. This drive provides a shortcut for access environment variables. Some examples:

    # Print the value of the "myVar" variable in the current scope:
    Write-Output -InputObject $myVar

    # Print the value of the "myVar" environment variable:
    Write-Output -InputObject $env:myVar

    # List all environment variables:
    Get-ChildItem -Path env:

With that said, this isn't really a GoCD question. If you have further questions about getting PS to do the things you want it to do, I recommend posting your question(s) to a PowerShell-specific forum.

Regards,
Jason Smyth

Nayan Makwana

unread,
Aug 23, 2022, 10:01:55 AM8/23/22
to go-cd
Thank you Jason for helping me out 
Reply all
Reply to author
Forward
0 new messages