Search in sources :

Example 21 with EnvVars

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();
}
Also used : Action(hudson.model.Action) User(hudson.model.User) ParameterValue(hudson.model.ParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) Test(org.junit.Test)

Example 22 with EnvVars

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());
}
Also used : Action(hudson.model.Action) User(hudson.model.User) StringParameterDefinition(hudson.model.StringParameterDefinition) StringParameterValue(hudson.model.StringParameterValue) ParameterValue(hudson.model.ParameterValue) StringParameterValue(hudson.model.StringParameterValue) FreeStyleBuild(hudson.model.FreeStyleBuild) MockFolder(org.jvnet.hudson.test.MockFolder) FreeStyleProject(hudson.model.FreeStyleProject) JobPropertyImpl(hudson.plugins.promoted_builds.JobPropertyImpl) Promotion(hudson.plugins.promoted_builds.Promotion) ManualCondition(hudson.plugins.promoted_builds.conditions.ManualCondition) EnvVars(hudson.EnvVars) PromotionProcess(hudson.plugins.promoted_builds.PromotionProcess) Test(org.junit.Test)

Example 23 with EnvVars

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;
}
Also used : EnvVars(hudson.EnvVars)

Example 24 with EnvVars

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);
}
Also used : EnvVars(hudson.EnvVars)

Example 25 with EnvVars

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;
}
Also used : FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) IOException(java.io.IOException)

Aggregations

EnvVars (hudson.EnvVars)64 Test (org.junit.Test)23 IOException (java.io.IOException)15 FilePath (hudson.FilePath)11 ClientConfiguration (com.amazonaws.ClientConfiguration)7 ArgumentListBuilder (hudson.util.ArgumentListBuilder)7 TaskListener (hudson.model.TaskListener)6 AbortException (hudson.AbortException)5 HashMap (java.util.HashMap)5 MavenModuleSet (hudson.maven.MavenModuleSet)4 FreeStyleProject (hudson.model.FreeStyleProject)4 ParameterValue (hudson.model.ParameterValue)4 Launcher (hudson.Launcher)3 GitException (hudson.plugins.git.GitException)3 LogTaskListener (hudson.util.LogTaskListener)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NodeJSInstallation (jenkins.plugins.nodejs.tools.NodeJSInstallation)3 ConduitAPIClient (com.uber.jenkins.phabricator.conduit.ConduitAPIClient)2 ConduitAPIException (com.uber.jenkins.phabricator.conduit.ConduitAPIException)2