Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
JENKINS-20705 - Environment Script does not work on Windows Master
- Loading branch information
1 parent
545b348
commit 2ad196a
Showing
9 changed files
with
167 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.lookout.jenkins.commands; | ||
|
||
public class Commands { | ||
|
||
public final static String POWER_SHELL = "powerShell"; | ||
public final static String BATCH_SCRIPT = "batchScript"; | ||
|
||
public static boolean isShebangs(String script) { | ||
if (script.startsWith("#!")) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/lookout/jenkins/commands/PowerShell.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.lookout.jenkins.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import hudson.FilePath; | ||
|
||
public class PowerShell { | ||
|
||
// Mostly stolen from managed-scripts-plugin | ||
public static String[] buildCommandLine(FilePath scriptFile) { | ||
List<String> cml = new ArrayList<String>(); | ||
cml.add("powershell.exe"); | ||
cml.add("-ExecutionPolicy"); | ||
cml.add("ByPass"); | ||
cml.add("& \'" + scriptFile.getRemote() + "\'"); | ||
|
||
return (String[]) cml.toArray(new String[cml.size()]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.lookout.jenkins.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import hudson.FilePath; | ||
import hudson.Util; | ||
|
||
public class Shebangs { | ||
|
||
public static String[] parseCommandLine(String script, FilePath scriptFile) { | ||
// Find first line, or just entire script if it's one line. | ||
int end = script.indexOf('\n'); | ||
if (end < 0) | ||
end = script.length(); | ||
|
||
String interpreter = script.substring(0, end).trim(); | ||
interpreter = interpreter.substring(2); | ||
|
||
List<String> cml = new ArrayList<String>(Arrays.asList(Util.tokenize(interpreter))); | ||
cml.add(scriptFile.getRemote()); | ||
|
||
return cml.toArray(new String[cml.size()]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.lookout.jenkins.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import hudson.FilePath; | ||
import hudson.tasks.Shell; | ||
import jenkins.model.Jenkins; | ||
|
||
public class UnixShell { | ||
|
||
public static String[] buildCommandLine(FilePath scriptFile) { | ||
Shell.DescriptorImpl shellDescriptor = Jenkins.getInstance() | ||
.getDescriptorByType(Shell.DescriptorImpl.class); | ||
final String shell = shellDescriptor.getShellOrDefault(scriptFile.getChannel()); | ||
|
||
List<String> cml = new ArrayList<String>(); | ||
cml.add(shell); | ||
cml.add("-xe"); | ||
cml.add(scriptFile.getRemote()); | ||
|
||
return (String[]) cml.toArray(new String[cml.size()]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.lookout.jenkins.commands; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import hudson.FilePath; | ||
|
||
public class WinBatch { | ||
|
||
// Mostly stolen from managed-scripts-plugin | ||
public static String[] buildCommandLine(FilePath scriptFile) { | ||
List<String> cml = new ArrayList<String>(); | ||
cml.add("cmd"); | ||
cml.add("/c"); | ||
cml.add("call"); | ||
cml.add(scriptFile.getRemote()); | ||
|
||
return (String[]) cml.toArray(new String[cml.size()]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters