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

On Tuesday, 23 August 2022 at 09:08:02 UTC-4 makwanan...@gmail.com wrote:

> I trying like this 
>
> [image: env_val.png][image: powershell.png]
>
> but non of the work for me to print the msg
> On Tuesday, August 23, 2022 at 6:27:18 PM UTC+5:30 
> jsm...@scimarketview.com wrote:
>
>> 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
>>
>>
>> On Tuesday, 23 August 2022 at 08:20:09 UTC-4 makwanan...@gmail.com wrote:
>>
>>> 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
>>> On Monday, August 22, 2022 at 8:28:35 PM UTC+5:30 
>>> jsm...@scimarketview.com wrote:
>>>
>>>> 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
>>>>
>>>>
>>>> On Monday, 22 August 2022 at 08:30:13 UTC-4 makwanan...@gmail.com 
>>>> wrote:
>>>>
>>>>> 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
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to go-cd+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/go-cd/9e68c255-6d02-46be-8d97-2c6acf20018en%40googlegroups.com.

Reply via email to