Skip to content

Commit

Permalink
[JENKINS-41759] Fixing failing credentials tests after refactor
Browse files Browse the repository at this point in the history
Some other tests are still failing...
  • Loading branch information
rsandell authored and abayer committed Feb 10, 2017
1 parent 331e432 commit d460eaf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Expand Up @@ -32,6 +32,7 @@
import org.jenkinsci.plugins.pipeline.modeldefinition.environment.DeclarativeEnvironmentContributorDescriptor;
import org.jenkinsci.plugins.pipeline.modeldefinition.model.CredentialsBindingHandler;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.jenkinsci.plugins.workflow.cps.CpsScript;
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper;
import org.kohsuke.stapler.DataBoundConstructor;

Expand All @@ -57,7 +58,14 @@ public String getCredentialsId() {
return credentialsId;
}

public void prepare(RunWrapper currentBuild) throws CredentialNotFoundException {
@Whitelisted
public void addParameters(CpsScript script, String envVarName, List<Map<String, Object>> list) throws CredentialNotFoundException {
RunWrapper currentBuild = (RunWrapper) script.getProperty("currentBuild");
prepare(currentBuild);
list.addAll(resolveParameters(envVarName));
}

private void prepare(RunWrapper currentBuild) throws CredentialNotFoundException {
CredentialsBindingHandler handler = CredentialsBindingHandler.forId(credentialsId, currentBuild.getRawBuild());
withCredentialsParameters = handler.getWithCredentialsParameters(credentialsId);
}
Expand Down
Expand Up @@ -230,7 +230,7 @@ public class ModelInterpreter implements Serializable {
List<Map<String, Object>> parameters = []
Set<Map.Entry<String, Credentials>> set = credentials.entrySet()
for (Map.Entry<String, Credentials> entry : set) {
entry.value.getScript(script).addParameters(entry.key, parameters)
entry.value.addParameters(script, entry.key, parameters)
}
parameters
}
Expand Down
Expand Up @@ -25,25 +25,18 @@
package org.jenkinsci.plugins.pipeline.modeldefinition.environment.impl

import org.jenkinsci.plugins.pipeline.modeldefinition.environment.DeclarativeEnvironmentContributorScript
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted
import org.jenkinsci.plugins.workflow.cps.CpsScript
import org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper

public class CredentialsScript extends DeclarativeEnvironmentContributorScript<Credentials> {

CredentialsScript(CpsScript script, Credentials contributor) {
super(script, contributor)
RunWrapper currentBuild = script.getProperty("currentBuild")
contributor.prepare(currentBuild)
}

@Override
List<String> generate(String key) {
return null //Not used because MutedGenerator
}

@Whitelisted
public void addParameters(String envVarName, List<Map<String, Object>> list) {
list.addAll(describable.resolveParameters(envVarName))
}

}

0 comments on commit d460eaf

Please sign in to comment.