Skip to content

Instantly share code, notes, and snippets.

@kaltepeter
Created April 15, 2018 03:04
Show Gist options
  • Save kaltepeter/e5cbe4b7c1ec3e0f2ea4c54f93ee520a to your computer and use it in GitHub Desktop.
Save kaltepeter/e5cbe4b7c1ec3e0f2ea4c54f93ee520a to your computer and use it in GitHub Desktop.
execute shell to create a file
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