Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting pwsh as powershell executable #111

Merged
merged 4 commits into from
Oct 10, 2019
Merged

Allow setting pwsh as powershell executable #111

merged 4 commits into from
Oct 10, 2019

Conversation

jetersen
Copy link
Member

@jetersen jetersen commented Oct 7, 2019

Upstream of jenkinsci/workflow-durable-task-step-plugin#122
added docker fixture test for pwsh.

This should allow us to create a pwsh step in workflow-durable-task-step

resolves #55
resolves #73
resolves #88

@jetersen
Copy link
Member Author

jetersen commented Oct 7, 2019

cc @slide @dwnusbaum

also atm PowerShellScript does not show up in the freestyle job.

Tested both on master and this branch.

Copy link
Contributor

@car-roll car-roll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I haven't really worked much on the Powershell side really, so I don't feel comfortable giving approval actuallly, nvm, looking it over again I think I was just being overly cautious :)

@jetersen
Copy link
Member Author

jetersen commented Oct 8, 2019

cc @jglick @gabloe @jtnord perhaps you want to review my changes?
I added a dedicated pwsh step instead of allowing the powershell step to choose edition. jenkinsci/workflow-durable-task-step-plugin#122

@@ -106,8 +117,8 @@ public String getScript() {
// Copy the helper script from the resources directory into the workspace
c.getPowerShellHelperFile(ws).copyFrom(getClass().getResource("powershellHelper.ps1"));

if (launcher.isUnix()) {
// There is no need to add a BOM with Open PowerShell
if (launcher.isUnix() || "pwsh".equals(powershellBinary)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: many launchers always say true and lie :-( (but this is existing issue)

The binary is pwsh.exe (and on windows is normally case insensitive - so this should allows pwsh pwsh.exe and all cases of that if I understand the intent here)

Copy link
Member Author

@jetersen jetersen Oct 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not have to specify pwsh.exe, pwsh is fine.
@jtnord this is existing logic that been working for quite awhile

see existing code

// Note: PowerShell core is now named pwsh. Workaround this issue on *nix systems by creating a symlink that maps 'powershell' to 'pwsh'.
String powershellBinary = "powershell";
String powershellArgs;
if (launcher.isUnix()) {
powershellArgs = "-NoProfile -NonInteractive";
} else {
powershellArgs = "-NoProfile -NonInteractive -ExecutionPolicy Bypass";
}
args.add(powershellBinary);
args.addAll(Arrays.asList(powershellArgs.split(" ")));
args.addAll(Arrays.asList("-Command", cmd));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not have to - but it is generally good practice to do so.
thus if you follow good practices then this will not work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

despite this being a String it is not currently user editable from jelly so I guess this is a moot point

@jetersen
Copy link
Member Author

jetersen commented Oct 8, 2019

@dwnusbaum I'd appreciate you casting a review, so if there is anything that needs changing. That would be favorable 😸

Copy link
Member

@dwnusbaum dwnusbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Casz thanks for the PR and for adding tests! I am not really familiar with PowerShell (Core), but given @gabloe's approval I trust that this makes sense in general.


@DataBoundSetter
public void setPowershellBinary(String powershellBinary) {
this.powershellBinary = powershellBinary;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do some validation here, or do you intentionally want to let users specify anything in case they've set up a symlink or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The UI only allows two options however from API it could by anything.

Do you see an issue with that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it some more, since jenkinsci/workflow-durable-task-step-plugin#122 is the only way users would be exposed to the change, and they wouldn't specify the actual binary, just the new pwsh step, I don't think validation is necessary.

It seems a bit confusing that we even have Jelly files in this plugin, since IIUC they are not currently used anywhere, because the steps in workflow-durable-step define their own config and help files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jelly files here should appear in FreeStyle but as I wrote in the PR description. This does not currently work for master branch nor this PR.

Should I try and do a git bisect to determine when PowerShell option disappeared from Jelly view?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that feature was provided by this plugin: https://github.com/jenkinsci/powershell-plugin?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, do you mind if I switch the powershell and pwsh to public static final string or do you prefer enum?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean, I think the code in the PR is good as-is, no changes necessary. I'm happy to merge it once the CI build passes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay 👍

Copy link
Contributor

@gabloe gabloe Oct 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the CI build is unavailable? Getting a 503 page.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think ci.jenkins.io is down right now (unfortunately a common occurrence these days). Looks like the infra team is investigating based on #jenkins-infra on IRC.

Co-Authored-By: Devin Nusbaum <dwnusbaum@users.noreply.github.com>
@jetersen jetersen closed this Oct 9, 2019
@jetersen
Copy link
Member Author

jetersen commented Oct 9, 2019

Triggering CI 😰

@jetersen jetersen reopened this Oct 9, 2019
@jetersen
Copy link
Member Author

Ci passed

@dwnusbaum dwnusbaum merged commit 0fca597 into jenkinsci:master Oct 10, 2019
@jetersen jetersen deleted the fix/pwsh branch October 11, 2019 05:20
@jetersen
Copy link
Member Author

🚢 📦 🚀

@jetersen
Copy link
Member Author

I'd really like for pwsh step to be available. So I would appreciate a release 😓

@car-roll
Copy link
Contributor

@Casz Looks like master is having an issue right now, hopefully it's just infra issues (unable to build windows image for tests). Once I get those resolved I'll get a release out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants