use of hudson.EnvVars in project promoted-builds-plugin by jenkinsci.
the class PromotionEnvironmentVariablesTest method shouldSetJobAndJobFullNames.
@Test
public void shouldSetJobAndJobFullNames() throws Descriptor.FormException, IOException, InterruptedException, ExecutionException, Exception {
// Assemble
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
User u = User.get("foo");
u.setFullName("Foobar");
SecurityContextHolder.getContext().setAuthentication(u.impersonate());
MockFolder parent = r.createFolder("Folder");
FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
promotionProcess.conditions.clear();
promotionProcess.conditions.add(new ManualCondition());
Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new ArrayList<ParameterValue>());
// Act
FreeStyleBuild build = project.scheduleBuild2(0).get();
build.setDisplayName("1234");
build.addAction(approvalAction);
build.save();
Promotion promotion = promotionProcess.considerPromotion2(build).get();
EnvVars env = promotion.getEnvironment(TaskListener.NULL);
// Assert
assertEquals("Folder/Project", env.get("PROMOTED_JOB_FULL_NAME"));
assertEquals("Project", env.get("PROMOTED_JOB_NAME"));
assertEquals("Foobar", env.get("PROMOTED_USER_NAME"));
assertEquals("foo", env.get("PROMOTED_USER_ID"));
assertEquals("1234", env.get("PROMOTED_DISPLAY_NAME"));
project.delete();
parent.delete();
}
use of hudson.EnvVars in project promoted-builds-plugin by jenkinsci.
the class PromotedEnvVarTokenMacroTest method testEnvironmentVariableExpansion.
@Test
public void testEnvironmentVariableExpansion() throws Exception {
// Assemble
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
User u = User.get("foo");
u.setFullName("Foobar");
SecurityContextHolder.getContext().setAuthentication(u.impersonate());
MockFolder parent = r.createFolder("Folder");
FreeStyleProject project = parent.createProject(FreeStyleProject.class, "Project");
JobPropertyImpl promotionProperty = new JobPropertyImpl(project);
PromotionProcess promotionProcess = promotionProperty.addProcess("promo");
promotionProcess.conditions.clear();
ManualCondition manualCondition = new ManualCondition();
manualCondition.getParameterDefinitions().add(new StringParameterDefinition("PROMOTION_PARAM", "defaultValue"));
promotionProcess.conditions.add(manualCondition);
Action approvalAction = new ManualCondition.ManualApproval(promotionProcess.getName(), new LinkedList<ParameterValue>());
TokenMacroExpressionRecorder recorder = new TokenMacroExpressionRecorder("${PROMOTION_ENV,var=\"PROMOTION_PARAM\"}");
promotionProcess.getBuildSteps().add(recorder);
// Act & promote
FreeStyleBuild build = project.scheduleBuild2(0).get();
build.addAction(approvalAction);
build.save();
Promotion promotion = promotionProcess.considerPromotion2(build, Arrays.asList((ParameterValue) new StringParameterValue("PROMOTION_PARAM", "FOO"))).get();
// Check results
EnvVars env = promotion.getEnvironment(TaskListener.NULL);
assertEquals("The PROMOTION_PARAM variable has not been injected", "FOO", env.get("PROMOTION_PARAM"));
assertEquals("The promotion variable value has not been resolved by the PROMOTION_PARAM macro", "FOO", recorder.getCaptured());
}
use of hudson.EnvVars in project hudson-2.x by hudson.
the class Run method getCharacteristicEnvVars.
/**
* Builds up the environment variable map that's sufficient to identify a process
* as ours. This is used to kill run-away processes via {@link ProcessTree#killAll(Map)}.
*/
public final EnvVars getCharacteristicEnvVars() {
EnvVars env = new EnvVars();
env.put("HUDSON_SERVER_COOKIE", Util.getDigestOf("ServerID:" + Hudson.getInstance().getSecretKey()));
env.put("BUILD_NUMBER", String.valueOf(number));
env.put("BUILD_ID", getId());
env.put("BUILD_TAG", "hudson-" + getParent().getName() + "-" + number);
env.put("JOB_NAME", getParent().getFullName());
return env;
}
use of hudson.EnvVars in project hudson-2.x by hudson.
the class Mailer method perform.
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {
if (debug) {
listener.getLogger().println("Running mailer");
}
// substitute build parameters
EnvVars env = build.getEnvironment(listener);
String recip = env.expand(recipients);
return new MailSender(recip, dontNotifyEveryUnstableBuild, sendToIndividuals, descriptor().getCharset()).execute(build, listener);
}
use of hudson.EnvVars in project hudson-2.x by hudson.
the class JavadocArchiver method perform.
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
listener.getLogger().println(Messages.JavadocArchiver_Publishing());
EnvVars env = build.getEnvironment(listener);
FilePath javadoc = build.getWorkspace().child(env.expand(javadocDir));
FilePath target = new FilePath(keepAll ? getJavadocDir(build) : getJavadocDir(build.getProject()));
try {
if (javadoc.copyRecursiveTo("**/*", target) == 0) {
if (build.getResult().isBetterOrEqualTo(Result.UNSTABLE)) {
// If the build failed, don't complain that there was no javadoc.
// The build probably didn't even get to the point where it produces javadoc.
listener.error(Messages.JavadocArchiver_NoMatchFound(javadoc, javadoc.validateAntFileMask("**/*")));
}
build.setResult(Result.FAILURE);
return true;
}
} catch (IOException e) {
Util.displayIOException(e, listener);
e.printStackTrace(listener.fatalError(Messages.JavadocArchiver_UnableToCopy(javadoc, target)));
build.setResult(Result.FAILURE);
return true;
}
// add build action, if javadoc is recorded for each build
if (keepAll)
build.addAction(new JavadocBuildAction(build));
return true;
}
Aggregations