private void populatePromotionParameters(List<String> params, Object promotionObj) { final Promotion promotion = (Promotion) promotionObj; for (ParameterValue value : promotion.getParameterValues()) { if (value instanceof StringParameterValue) { if (StringUtils.isNotBlank(((StringParameterValue) value).value)) { params.add("<strong>" + value.getName() + "</strong>: " + ((StringParameterValue) value).value); } } else if (value instanceof FileParameterValue) { params.add("<strong>" + value.getName() + "</strong>: " + ((FileParameterValue) value).getLocation()); } else if (value instanceof BooleanParameterValue) { if (((BooleanParameterValue) value).value) { params.add("<strong>" + value.getName() + "</strong>: " + Boolean.toString(((BooleanParameterValue) value).value)); } } // TODO: there are more types } }
@Issue("JENKINS-32943") @Test public void fileCredentials() throws Exception { story.addStep(new Statement() { @Override public void evaluate() throws Throwable { DockerTestUtil.assumeDocker(); File f = tmp.newFile("some-file"); FileUtils.write(f, "some-content"); FileItem fi = new FileParameterValue.FileItemImpl(f); FileCredentialsImpl fc = new FileCredentialsImpl(CredentialsScope.GLOBAL, "secretfile", "", fi, fi.getName(), null); CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), fc); WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "prj"); p.setDefinition(new CpsFlowDefinition( "node {\n" + " withDockerContainer('ubuntu') {\n" + " withCredentials([[$class: 'FileBinding', credentialsId: 'secretfile', variable: 'FILE']]) {\n" + " sh 'cat $FILE'\n" + " }\n" + " }\n" + " withCredentials([[$class: 'FileBinding', credentialsId: 'secretfile', variable: 'FILE']]) {\n" + " withDockerContainer('ubuntu') {\n" + " sh 'tr \"a-z\" \"A-Z\" < $FILE'\n" + " }\n" + " }\n" + "}", true)); WorkflowRun b = story.j.assertBuildStatusSuccess(p.scheduleBuild2(0)); story.j.assertLogContains("some-content", b); story.j.assertLogContains("SOME-CONTENT", b); } }); }