Issue
I'm trying to use a simple FreeStyleJob SCM , and set the credentialId UUID from build parameter. The problem is, it seems the credentials is not parsing the parameter correctly.
scm {
git {
remote {
github('\${MY_REPO_HANDLE}', 'ssh')
credentials('\${MY_REPO_CREDENTIALS}')
}
branch('\${MY_BRANCH}')
}
}
My MY_REPO_CREDENTIALS is a simple String parameter
stringParam {
name("MY_REPO_CREDENTIALS")
defaultValue("teste-credential")
}
Log:
Warning: CredentialId "${MY_REPO_CREDENTIALS}" could not be found.
UPDATE
This Jenkins Job is created by another Jenkins Job using DSL external. In resume, Job 1 whenn triggered will create the Job 2 on jenkins. When I try to use "$ (without \) the job will fail because this parameter doesn't exist on Job 1 context.
job config.xml:
<scm class="hudson.plugins.git.GitSCM">
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>[email protected]:${MY_REPO_HANDLE}.git</url>
<credentialsId>${MY_REPO_CREDENTIALS}</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>${MY_BRANCH}</name>
</hudson.plugins.git.BranchSpec>
</branches>
<configVersion>2</configVersion>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<gitTool>Default</gitTool>
<browser class="hudson.plugins.git.browser.GithubWeb">
<url>https://github.com/${MY_REPO_HANDLE}/</url>
</browser>
</scm>
Solution
The final solution was set the ssh agent before build, using wrapper:
wrappers {
sshAgent("\${MY_REPO_CREDENTIALS}")
}
keepDependencies(false)
scm {
git {
remote {
github("\${MY_REPO_HANDLE}", 'ssh')
}
branch("\${MY_BRANCH}")
}
}
Answered By - B Berdugo
Answer Checked By - Marie Seifert (JavaFixing Admin)