Created
April 15, 2018 03:04
-
-
Save kaltepeter/e5cbe4b7c1ec3e0f2ea4c54f93ee520a to your computer and use it in GitHub Desktop.
execute shell to create a file
This file contains hidden or 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
def executeOnShell(String command) { | |
return executeOnShell(command, new File(System.properties.'user.dir')) | |
} | |
private def executeOnShell(String command, File workingDir) { | |
println command | |
def process = new ProcessBuilder(addShellPrefix(command)) | |
.directory(workingDir) | |
.redirectErrorStream(true) | |
.start() | |
process.inputStream.eachLine {println it} | |
process.waitFor(); | |
return process.exitValue() | |
} | |
private def addShellPrefix(String command) { | |
commandArray = new String[3] | |
commandArray[0] = "sh" | |
commandArray[1] = "-c" | |
commandArray[2] = command | |
return commandArray | |
} | |
def npmrcFile = """ | |
_auth="yourtoken" | |
email=email-noreply@merrillcorp.com | |
always-auth=true | |
progress="=" | |
""" | |
def gitconfig = """ | |
[user] | |
email = email-noreply@merrillcorp.com | |
name = Jenkins | |
""" | |
executeOnShell("echo ${npmrc} >> /home/jenkins/node/.npmrc") | |
executeOnShell("cat /home/jenkins/node/.npmrc") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment