Comment puis-je consulter un référentiel Subversion qui nécessite des informations d'identification d'utilisateur, via un script groovy de pipeline Jenkins? Il semble que la commande svn
intégrée ne prenne pas en charge les informations d'identification, j'ai donc essayé du code comme celui-ci:
node {
stage 'checkout'
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: '34761a89-1402-47d7-96e2-aec22ffdc50b',
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh "svn co https://trac.nci.org.au/svn/cable/branches/$SVN_BRANCH --username $USERNAME --password $PASSWORD cable_branch"
}
}
Mais cela échoue avec
groovy.lang.MissingPropertyException: No such property: USERNAME for class: groovy.lang.Binding
at groovy.lang.Binding.getVariable(Binding.Java:63)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.Java:224)
at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.Java:241)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.Java:238)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.Java:221)
at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.Java:221)
at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.Java:23)
at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.Java:17)
at WorkflowScript.run(WorkflowScript:5)
at ___cps.transform___(Native Method)
...
Qu'est-ce que je rate?
Vous pouvez utiliser l'étape Générateur d'extraits pour SCM général. Cela affiche les options de configuration Subversion familières et prend les informations d'identification comme paramètre comme d'habitude.
Le générateur d'extraits de code produira une représentation un peu moche de vos sélections de paramètres et ressemble à ceci:
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: '',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[credentialsId: '34761a89-1402-47d7-96e2-aec22ffdc50b',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: 'cable_branch',
remote: "https://trac.nci.org.au/svn/cable/branches/$SVN_BRANCH"]],
workspaceUpdater: [$class: 'UpdateUpdater']])
Notez que la section remote utilise des guillemets doubles, afin que la variable $ SVN_BRANCH soit correctement remplacée.