private BuildCommand setupSecrets() { List<EnvironmentVariableContext.EnvironmentVariable> secrets = environmentVariableContext().getSecureEnvironmentVariables(); ArrayList<BuildCommand> commands = new ArrayList<>(); for (EnvironmentVariableContext.EnvironmentVariable secret : secrets) { commands.add(secret(secret.value())); } return BuildCommand.compose(commands); }
private BuildCommand setupEnvironmentVariables() { EnvironmentVariableContext context = environmentVariableContext(); ArrayList<BuildCommand> commands = new ArrayList<>(); commands.add(export("GO_SERVER_URL")); for (String property : context.getPropertyKeys()) { commands.add(export(property, context.getProperty(property), context.isPropertySecure(property))); } return BuildCommand.compose(commands); }
public BuildCommand updateTo(String baseDir, RevisionContext revisionContext) { Revision revision = revisionContext.getLatestRevision(); String workingDir = material.workingdir(new File(baseDir)).getPath(); return compose( secret(material.getPassword()), execTfsCheckout(material, revision, workingDir) ); }
private BuildCommand cloneIfNeeded(String workDir, int cloneDepth) { return compose( mkdirs(workDir).setTest(test("-nd", workDir)), cleanWorkingDir(workDir), cmdClone(workDir, cloneDepth)); }
private BuildCommand cleanupUnversionedFiles(String workingDir) { return compose( echo("[GIT] Cleaning all unversioned files in working copy"), exec("git", "submodule", "foreach", "--recursive", "git", "clean", "-fdd") .setTest(hasSubmodules(workingDir)), exec("git", "clean", "-dff")) .setWorkingDirectoryRecursively(workingDir); }
private BuildCommand cloneIfNeeded(String workDir) { return compose( mkdirs(workDir).setTest(test("-nd", workDir)), cleanWorkingDir(workDir), cmdClone(workDir).setTest(isNotRepository(workDir)) ); }
private BuildCommand freshCheckout(String workingDir, Revision revision) { return compose( echoWithPrefix("Checking out a fresh copy"), cleandir(workingDir).setTest(test("-d", workingDir)), mkdirs(workingDir).setTest(test("-nd", workingDir)), checkout(workingDir, revision) ); }
@Test public void shouldNotLeakSecretWhenExceptionHappened() throws Exception { runBuild(compose( secret("the-answer-is-42"), error("error: the-answer-is-42")), Failed); assertThat(console.output(), containsString("error: ******")); assertThat(console.output(), not(containsString("the-anwser-is-42"))); } }
@Test public void testReportCurrentStatus() { runBuild(compose( reportCurrentStatus(Preparing), reportCurrentStatus(Building), reportCurrentStatus(Completing)), Passed); assertThat(statusReporter.status(), is(Arrays.asList(Preparing, Building, Completing, Completed))); }
@Test public void shouldNotRunCommandWithRunIfFailedIfBuildIsPassing() { runBuild(compose( echo("on pass"), echo("on failure").runIf("failed")), Passed); assertThat(console.asList(), is(Collections.singletonList("on pass"))); }
private BuildCommand cleanWorkingDir() { if (!assignment.shouldCleanWorkingDir()) { return noop(); } return BuildCommand.compose( cleandir(workingDirectory()), echoWithPrefix("Cleaning working directory \"$%s\" since stage is configured to clean working directory", workingDirectory()) ).setTest(test("-d", workingDirectory())); }
@Test @RunIf(value = EnhancedOSChecker.class, arguments = {DO_NOT_RUN_ON, OSChecker.WINDOWS}) public void shouldNotLeakSecretsToConsoleLog() { runBuild(compose(secret("topsecret"), exec("not-not-not-exist", "topsecret")), Failed); assertThat(console.output(), containsString("not-not-not-exist ******")); assertThat(console.output(), not(containsString("topsecret"))); }
@Test public void secretMaskValuesInExecOutput() throws Exception { runBuild(compose( secret("42"), exec("echo", "the answer is 42")), Passed); assertThat(console.output(), containsString("the answer is ******")); }
@Test public void shouldRunCommandWithRunIfFailedIfBuildIsFailed() { runBuild(compose( fail("force failure"), echo("on failure").runIf("failed")), Failed); assertThat(console.lastLine(), is("on failure")); }
@Test public void execUseOverriddenSystemEnvValue() throws Exception { runBuild(compose( export(pathSystemEnvName(), "/foo/bar", false), execEchoEnv(pathSystemEnvName())), Passed); assertThat(console.lastLine(), is("/foo/bar")); }
@Test public void shouldNotFailBuildWhenTestEqWithComposedCommandOutputFail() { runBuild(echo("foo").setTest(test("-eq", "42", compose(fail("42")))), Passed); assertThat(statusReporter.singleResult(), is(Passed)); assertThat(console.output(), containsString("foo")); } }
@Test public void shouldNotFailBuildWhenComposedTestCommandFail() { runBuild(echo("foo").setTest(compose(echo(""), fail(""))), Passed); assertThat(statusReporter.singleResult(), is(JobResult.Passed)); }
private BuildCommand runSingleBuilder(Builder builder) { String runIfConfig = builder.resolvedRunIfConfig().toString(); return BuildCommand.compose( echoWithPrefix("Current job status: passed"), echoWithPrefix("Current job status: failed").runIf("failed"), echoWithPrefix("Task: %s", builder.getDescription()).runIf(runIfConfig), builder.buildCommand() .runIf(runIfConfig) .setOnCancel(runCancelTask(builder.getCancelBuilder()))).runIf(runIfConfig); }