Last active
May 20, 2020 06:54
-
-
Save michaelsauter/16bd497a2052b014f31fb40da8ad33d7 to your computer and use it in GitHub Desktop.
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
import org.ods.service.ServiceRegistry | |
import org.ods.util.GitUtil | |
import org.ods.util.Project | |
def runOnAgentPod(Project project, boolean condition, Closure block) { | |
if (condition) { | |
def git = ServiceRegistry.instance.get(GitUtil) | |
dir(env.WORKSPACE) { | |
stash(name: 'wholeWorkspace', includes: '**/*,**/.git', useDefaultExcludes: false) | |
} | |
def bitbucketHost = env.BITBUCKET_HOST | |
def podLabel = "mro-jenkins-agent-${env.BUILD_NUMBER}" | |
node(podLabel) { | |
git.configureUser() | |
unstash("wholeWorkspace") | |
withCredentials([usernamePassword(credentialsId: project.services.bitbucket.credentials.id, usernameVariable: 'BITBUCKET_USER', passwordVariable: 'BITBUCKET_PW')]) { | |
def urlWithCredentials = "https://${java.net.URLEncoder.encode(env.BITBUCKET_USER, "UTF-8")}:${java.net.URLEncoder.encode(env.BITBUCKET_PW, "UTF-8")}@${bitbucketHost}" | |
writeFile(file: "${env.HOME}/.git-credentials", text: urlWithCredentials) | |
sh(script: "git config --global credential.helper store", label : "setup credential helper") | |
} | |
block() | |
} | |
} else { | |
block() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment