Package hudson

Examples of hudson.EnvVars


    @Override
    public String evaluate(AbstractBuild<?, ?> context, TaskListener listener, String macroName)
            throws MacroEvaluationException, IOException, InterruptedException {       
        // do some environment variable substitution
        try {
            EnvVars env = context.getEnvironment(listener);
            path = env.expand(path);
        } catch(Exception e) {
            listener.error("Error retrieving environment");
        }
       
        if(!context.getWorkspace().child(path).exists()) {
View Full Code Here


    }

    @Test
    public void testEscapedToken() throws IOException, InterruptedException {
        build = mock(AbstractBuild.class);
        EnvVars testVars = new EnvVars();
        testVars.put("FOO", "BAR");
        when(build.getEnvironment(listener)).thenReturn(testVars);

        assertEquals("\\BAR", ContentBuilder.transformText("\\${ENV, var=\"FOO\"}", publisher, build, listener));
    }
View Full Code Here

    }

    public FormValidation validateFormRecipientList(String recipientList) {
        // Try and convert the recipient string to a list of InternetAddress. If this fails then the validation fails.
        try {
            convertRecipientString(recipientList, new EnvVars(), TO);
            convertRecipientString(recipientList, new EnvVars(), BCC);
            convertRecipientString(recipientList, new EnvVars(), CC);
            return FormValidation.ok();
        } catch (AddressException e) {
            return FormValidation.error(e.getMessage() + ": \"" + e.getRef() + "\"");
        } catch(UnsupportedEncodingException e) {
            return FormValidation.error(e.getMessage());
View Full Code Here

            AttachmentUtils.attachBuildLog(context, multipart, compressBuildLog || context.getTrigger().getEmail().getCompressBuildLog());
        }

        msg.setContent(multipart);

        EnvVars env = null;
        try {
            env = context.getBuild().getEnvironment(context.getListener());
        } catch (Exception e) {
            context.getListener().getLogger().println("Error retrieving environment vars: " + e.getMessage());
            // create an empty set of env vars
            env = new EnvVars();
        }
       
        // Get the recipients from the global list of addresses
        Set<InternetAddress> to = new LinkedHashSet<InternetAddress>();
        Set<InternetAddress> cc = new LinkedHashSet<InternetAddress>();
View Full Code Here

     * {@link MavenProcessFactory}), but setting the environment variable explicitly is still
     * useful in case this Maven forks other Maven processes via normal way. See HUDSON-3644.
     */
    @Override
    public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
        EnvVars envs = super.getEnvironment(log);

        // We need to add M2_HOME and the mvn binary to the PATH so if Maven
        // needs to run Maven it will pick the correct one.
        // This can happen if maven calls ANT which itself calls Maven
        // or if Maven calls itself e.g. maven-release-plugin
View Full Code Here

          PrintStream logger = listener.getLogger();
            FilePath remoteSettings = null, remoteGlobalSettings = null;

            try {
             
                EnvVars envVars = getEnvironment(listener);
                MavenInstallation mvn = project.getMaven();
                if(mvn==null)
                    throw new AbortException(Messages.MavenModuleSetBuild_NoMavenConfigured());

                mvn = mvn.forEnvironment(envVars).forNode(Computer.currentComputer().getNode(), listener);
               
                MavenInformation mavenInformation = getModuleRoot().act( new MavenVersionCallable( mvn.getHome() ));
               
                String mavenVersion = mavenInformation.getVersion();
               
                MavenBuildInformation mavenBuildInformation = new MavenBuildInformation( mavenVersion );
               
                setMavenVersionUsed( mavenVersion );

                LOGGER.fine(getFullDisplayName()+" is building with mavenVersion " + mavenVersion + " from file " + mavenInformation.getVersionResourcePath());

                if(!project.isAggregatorStyleBuild()) {
                    parsePoms(listener, logger, envVars, mvn, mavenVersion);
                    // start module builds
                    logger.println("Triggering "+project.getRootModule().getModuleName());
                    project.getRootModule().scheduleBuild(new UpstreamCause((Run<?,?>)MavenModuleSetBuild.this));
                } else {
                    // do builds here
                    try {
                        List<BuildWrapper> wrappers = new ArrayList<BuildWrapper>();
                        for (BuildWrapper w : project.getBuildWrappersList())
                            wrappers.add(w);
                        ParametersAction parameters = getAction(ParametersAction.class);
                        if (parameters != null)
                            parameters.createBuildWrappers(MavenModuleSetBuild.this,wrappers);

                        for( BuildWrapper w : wrappers) {
                            Environment e = w.setUp(MavenModuleSetBuild.this, launcher, listener);
                            if(e==null)
                                return (r = Result.FAILURE);
                            buildEnvironments.add(e);
                            e.buildEnvVars(envVars); // #3502: too late for getEnvironment to do this
                        }

                      // run pre build steps
                      if(!preBuild(listener,project.getPrebuilders())
                        || !preBuild(listener,project.getPostbuilders())
                        || !preBuild(listener,project.getPublishers())){
                        r = FAILURE;
                            return r;
                      }

                      if(!build(listener,project.getPrebuilders().toList())){
                        r = FAILURE;
                            return r;
                  }

                        String settingsConfigId = project.getSettingConfigId();
                        if (StringUtils.isNotBlank(settingsConfigId)) {
                            SettingConfig settingsConfig = SettingsProviderUtils.findSettings(settingsConfigId);
                            if (settingsConfig == null) {
                                logger.println(" your Apache Maven build is setup to use a config with id " + settingsConfigId
                                                   + " but cannot find the config");
                            } else {
                                logger.println("using settings config with name " + settingsConfig.name);
                                if (settingsConfig.content != null ) {
                                    remoteSettings = SettingsProviderUtils.copyConfigContentToFilePath( settingsConfig, getWorkspace() );
                                    project.setAlternateSettings( remoteSettings.getRemote() );
                                }
                            }
                        }

                        String globalSettingsConfigId = project.getGlobalSettingConfigId();
                        if (StringUtils.isNotBlank(globalSettingsConfigId)) {
                            SettingConfig settingsConfig = SettingsProviderUtils.findSettings(globalSettingsConfigId);
                            if (settingsConfig == null) {
                                logger.println(" your Apache Maven build is setup to use a global settings config with id " + globalSettingsConfigId
                                                   + " but cannot find the config");
                            } else {
                                logger.println("using global settings config with name " + settingsConfig.name);
                                if (settingsConfig.content != null ) {
                                    remoteGlobalSettings = SettingsProviderUtils.copyConfigContentToFilePath( settingsConfig, getWorkspace() );
                                    project.globalSettingConfigPath = remoteGlobalSettings.getRemote();
                                }
                            }
                        } else {
                          // make sure the transient field is clean
                          project.globalSettingConfigPath = null;
                        }

                        parsePoms(listener, logger, envVars, mvn, mavenVersion); // #5428 : do pre-build *before* parsing pom
                        SplittableBuildListener slistener = new SplittableBuildListener(listener);
                        proxies = new HashMap<ModuleName, ProxyImpl2>();
                        List<ModuleName> changedModules = new ArrayList<ModuleName>();
                       
                        if (project.isIncrementalBuild() && !getChangeSet().isEmptySet()) {
                            changedModules.addAll(getUnbuildModulesSinceLastSuccessfulBuild());
                        }

                        for (MavenModule m : project.sortedActiveModules) {
                            MavenBuild mb = m.newBuild();
                            // JENKINS-8418
                            mb.setBuiltOnStr( getBuiltOnStr() );
                            // Check if incrementalBuild is selected and that there are changes -
                            // we act as if incrementalBuild is not set if there are no changes.
                            if (!MavenModuleSetBuild.this.getChangeSet().isEmptySet()
                                && project.isIncrementalBuild()) {
                                //If there are changes for this module, add it.
                                // Also add it if we've never seen this module before,
                                // or if the previous build of this module failed or was unstable.
                                if ((mb.getPreviousBuiltBuild() == null) ||
                                    (!getChangeSetFor(m).isEmpty())
                                    || (mb.getPreviousBuiltBuild().getResult().isWorseThan(Result.SUCCESS))) {
                                    changedModules.add(m.getModuleName());
                                }
                            }

                            mb.setWorkspace(getModuleRoot().child(m.getRelativePath()));
                            proxies.put(m.getModuleName(), mb.new ProxyImpl2(MavenModuleSetBuild.this,slistener));
                        }

                        // run the complete build here

                        // figure out the root POM location.
                        // choice of module root ('ws' in this method) is somewhat arbitrary
                        // when multiple CVS/SVN modules are checked out, so also check
                        // the path against the workspace root if that seems like what the user meant (see issue #1293)
                        String rootPOM = project.getRootPOM(envVars); // JENKINS-13822
                        FilePath pom = getModuleRoot().child(rootPOM);
                        FilePath parentLoc = getWorkspace().child(rootPOM);
                        if(!pom.exists() && parentLoc.exists())
                            pom = parentLoc;

                       
                        final ProcessCache.MavenProcess process;
                       
                        boolean maven3orLater = mavenBuildInformation.isMaven3OrLater();
                        if ( maven3orLater )
                        {
                            LOGGER.fine( "using maven 3 " + mavenVersion );
                            process =
                                MavenBuild.mavenProcessCache.get( launcher.getChannel(), slistener,
                                                                  new Maven3ProcessFactory( project, launcher, envVars, getMavenOpts(listener, envVars),
                                                                                            pom.getParent() ) );
                        }
                        else
                        {
                            LOGGER.fine( "using maven 2 " + mavenVersion );
                            process =
                                MavenBuild.mavenProcessCache.get( launcher.getChannel(), slistener,
                                                                  new MavenProcessFactory( project, launcher, envVars,getMavenOpts(listener, envVars),
                                                                                           pom.getParent() ) );
                        }
                        ArgumentListBuilder margs = new ArgumentListBuilder().add("-B").add("-f", pom.getRemote());
                        FilePath localRepo = project.getLocalRepository().locate(MavenModuleSetBuild.this);
                        if(localRepo!=null)
                            margs.add("-Dmaven.repo.local="+localRepo.getRemote());

                        if (project.globalSettingConfigPath != null)
                            margs.add("-gs" , project.globalSettingConfigPath);


                       
                        // If incrementalBuild is set
                        // and the previous build didn't specify that we need a full build
                        // and we're on Maven 2.1 or later
                        // and there's at least one module listed in changedModules,
                        // then do the Maven incremental build commands.
                        // If there are no changed modules, we're building everything anyway.
                        boolean maven2_1orLater = new ComparableVersion (mavenVersion).compareTo( new ComparableVersion ("2.1") ) >= 0;
                        boolean needsFullBuild = getPreviousCompletedBuild() != null &&
                            getPreviousCompletedBuild().getAction(NeedsFullBuildAction.class) != null;
                        if (project.isIncrementalBuild() && !needsFullBuild && maven2_1orLater && !changedModules.isEmpty()) {
                            margs.add("-amd");
                            margs.add("-pl", Util.join(changedModules, ","));
                        }

                        if (project.getAlternateSettings() != null) {
                            if (IOUtils.isAbsolute(project.getAlternateSettings())) {
                                margs.add("-s").add(project.getAlternateSettings());
                            } else {
                                FilePath mrSettings = getModuleRoot().child(project.getAlternateSettings());
                                FilePath wsSettings = getWorkspace().child(project.getAlternateSettings());
                                if (!wsSettings.exists() && mrSettings.exists())
                                    wsSettings = mrSettings;
                               
                                margs.add("-s").add(wsSettings.getRemote());
                            }
                        }

                       
                        final List<MavenArgumentInterceptorAction> argInterceptors = this.getBuild().getActions(MavenArgumentInterceptorAction.class);
                       
            // find the correct maven goals and options, there might by an action overruling the defaults
                        String goals = project.getGoals(); // default
                        for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) {
                          final String goalsAndOptions = mavenArgInterceptor.getGoalsAndOptions((MavenModuleSetBuild)this.getBuild());
              if(StringUtils.isNotBlank(goalsAndOptions)){
                            goals = goalsAndOptions;
                                // only one interceptor is allowed to overwrite the whole "goals and options" string
                            break;
                          }
            }
            margs.addTokenized(envVars.expand(goals));

            // enable the interceptors to change the whole command argument list
            // all available interceptors are allowed to modify the argument list
            for (MavenArgumentInterceptorAction mavenArgInterceptor : argInterceptors) {
              final ArgumentListBuilder newMargs = mavenArgInterceptor.intercept(margs, (MavenModuleSetBuild)this.getBuild());
View Full Code Here

                    return Result.FAILURE;
                }
                buildEnvironments.add(e);
            }

            EnvVars envVars = getEnvironment(listener); // buildEnvironments should be set up first
           
            MavenInstallation mvn = getProject().getParent().getMaven();
           
            mvn = mvn.forEnvironment(envVars).forNode(Computer.currentComputer().getNode(), listener);
           
View Full Code Here

        super(project, buildDir);
    }

    @Override
    public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
        EnvVars envs = super.getEnvironment(log);

        String opts = getMavenOpts(log,envs);

        if(opts!=null)
            envs.put("MAVEN_OPTS", opts);

        return envs;
    }
View Full Code Here

        checkRecipients(build6, "A", "K", "U", "W");
    }

    private static void checkRecipients(final Build build, final String... inAuthors) throws AddressException {
        ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(null, build, new Launcher.LocalLauncher(StreamTaskListener.fromStdout()), new StreamBuildListener(System.out, Charset.defaultCharset()));
        EnvVars envVars = new EnvVars();
        Set<InternetAddress> to = new HashSet<InternetAddress>();
        Set<InternetAddress> cc = new HashSet<InternetAddress>();
        Set<InternetAddress> bcc = new HashSet<InternetAddress>();
        FailingTestSuspectsRecipientProvider provider = new FailingTestSuspectsRecipientProvider();
        provider.addRecipients(context, envVars, to, cc, bcc);
View Full Code Here

        return ChangeLogSet.createEmpty(this);
    }

    @Override
    public EnvVars getEnvironment(TaskListener log) throws IOException, InterruptedException {
        EnvVars env = super.getEnvironment(log);
        FilePath ws = getWorkspace();
        if (ws!=null)   // if this is done very early on in the build, workspace may not be decided yet. see HUDSON-3997
            env.put("WORKSPACE", ws.getRemote());
        // servlet container may have set CLASSPATH in its launch script,
        // so don't let that inherit to the new child process.
        // see http://www.nabble.com/Run-Job-with-JDK-1.4.2-tf4468601.html
        env.put("CLASSPATH","");

        JDK jdk = project.getJDK();
        if (jdk != null) {
            Computer computer = Computer.currentComputer();
            if (computer != null) { // just in case were not in a build
View Full Code Here

TOP

Related Classes of hudson.EnvVars

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.