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

Add an option to load the PowerShell profile #130

Merged
merged 2 commits into from
Mar 31, 2021

Conversation

ofosos
Copy link
Contributor

@ofosos ofosos commented Feb 9, 2021

Hey Team,
I would like to be able to load the PowerShell profile on the agent. This change is a step in that direction.

Please be kind. I ran the unit tests, but I'm not sure this will work, any ideas on how to test this properly?

Cheers, Mark

@@ -48,6 +48,7 @@
public final class PowershellScript extends FileMonitoringTask {
private final String script;
private String powershellBinary = "powershell";
private boolean loadProfile = false;
Copy link
Member

Choose a reason for hiding this comment

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

false is the default

Suggested change
private boolean loadProfile = false;
private boolean loadProfile;

@@ -63,6 +64,11 @@ public void setPowershellBinary(String powershellBinary) {
this.powershellBinary = powershellBinary;
}

public boolean isLoadProfile() { return loadProfile; }
Copy link
Member

Choose a reason for hiding this comment

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

use line breaks, to match the code style in the file

Suggested change
public boolean isLoadProfile() { return loadProfile; }
public boolean isLoadProfile() {
return loadProfile;
}

public boolean isLoadProfile() { return loadProfile; }

@DataBoundSetter
public void setLoadProfile(boolean loadProfile) { this.loadProfile = loadProfile; }
Copy link
Member

Choose a reason for hiding this comment

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

use line breaks, to match the code style in the file

Suggested change
public void setLoadProfile(boolean loadProfile) { this.loadProfile = loadProfile; }
public void setLoadProfile(boolean loadProfile) {
this.loadProfile = loadProfile;
}

@@ -7,4 +7,7 @@
<f:entry field="powershellBinary" title="Executable">
<f:select />
</f:entry>
<f:entry field="loadProfile" title="Load Profile">
Copy link
Member

Choose a reason for hiding this comment

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

you could also help add text by creating a file called:
help-loadProfile.html in the same directory

only if you think it's needed though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's rather obvious, what this switch does. So I would go without a help text. But thanks for the pointer!

@ofosos
Copy link
Contributor Author

ofosos commented Feb 10, 2021

Hey, @timja I incorporated your changes.

@car-roll
Copy link
Contributor

@ofosos
Copy link
Contributor Author

ofosos commented Feb 12, 2021

Hey @car-roll, I added to test to see if the flag is present in the current process. That's not really nice, but it looks better than changing profiles on developer machines ;)

Is this sufficient for you?

@car-roll
Copy link
Contributor

@ofosos admittedly I don't really know about PowerShell and profiles. Is the test somehow validating that the profile has been successfully loaded? I just see assertions for script launch success.

@ofosos
Copy link
Contributor Author

ofosos commented Feb 18, 2021

@car-roll The thing is, afaik we can't check that the profile has been loaded. Unless we modify the PowerShell profile and say include a variable. However it's kind of bad to modify every developers profile. So what we do instead is this: We spin up a powershell and the PowerShell script checks the flags of the current process (the powershell process) and returns success iff this includes the -NoProfile option. We check that the normal state is success and the return code is failure, when we pass the option to load the profiles.

@ofosos
Copy link
Contributor Author

ofosos commented Mar 2, 2021

@car-roll ping

@car-roll
Copy link
Contributor

@timja looks like your comments were all addressed in this PR. Anything else you would like to add?

@timja
Copy link
Member

timja commented Mar 31, 2021

Lgtm

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.

3 participants