Reputation: 31714
I want to customize the profile of the PS sessions Jenkins runs
I copied my profile to pretty much every possible location and ran this in a pipeline to confirm it's there, and its contents are correct:
powershell 'cat $PsHome\\Profile.ps1'
In the profile I set some aliases and environment variables
In PowerShell steps though if I check the aliases list and env vars I don't see the changes my profile contains:
powershell 'ls alias:'
powershell 'ls env:'
It doesn't look like Jenkins is running PowerShell with -noprofile: https://github.com/jenkinsci/powershell-plugin/blob/d3e8aec4074bdfa5f5032c71a3e6ba4a3c6c8340/src/main/java/hudson/plugins/powershell/PowerShell.java
Why isn't my profile being executed?
Upvotes: 3
Views: 1037
Reputation: 734
The powershell
command in a Pipeline job is not coming from the PowerShell plugin, as your post seems to assume.
The PowerShell plugin is only meant to add an Execute PowerShell step on Freestyle jobs and doesn't support pipelines.
Does this plugin support pipelines? No, but there is a powershell step provided by the Pipeline: Nodes and Processes plugin
They were experiencing the opposite situation, where profiles were always loaded, and the problem was how to avoid them when needed. A new PR mas merged recently to integrate a switch to choose whether profiles should be loaded or not
The implementation of powershell for Pipeline jobs comes from the Pipeline: Nodes and Processes plugin (a.k.a. workflow-durable-task-step-plugin) and currently, it doesn't include a parameter to enable disable loading Profiles.
The relevant files are here and here, in case you can get your head around them and create a new PR with the additional parameter.
The project in GitLab seems to have Issues disabled, so no reporting/requesting is possible.
Upvotes: 4