/** * Overrides all values in the map by the given map. Expressions in values will be expanded. * See {@link #override(String, String)}. * @return {@code this} */ public EnvVars overrideExpandingAll(@Nonnull Map<String,String> all) { for (String key : new OverrideOrderCalculator(this, all).getOrderedVariableNames()) { override(key, expand(all.get(key))); } return this; }
@Override public Proc launch(ProcStarter ps) throws IOException { if (!ps.quiet) { maskedPrintCommandLine(ps.commands, ps.masks, ps.pwd); } EnvVars jobEnv = inherit(ps.envs); // replace variables in command line String[] jobCmd = new String[ps.commands.size()]; for ( int idx = 0 ; idx < jobCmd.length; idx++ ) jobCmd[idx] = jobEnv.expand(ps.commands.get(idx)); return new LocalProc(jobCmd, Util.mapToEnv(jobEnv), ps.reverseStdin ?LocalProc.SELFPUMP_INPUT:ps.stdin, ps.reverseStdout?LocalProc.SELFPUMP_OUTPUT:ps.stdout, ps.reverseStderr?LocalProc.SELFPUMP_OUTPUT:ps.stderr, toFile(ps.pwd)); }
public JDK forEnvironment(EnvVars environment) { return new JDK(getName(), environment.expand(getHome())); }
/** * Build up the environment variables toward the Maven launch. */ protected void buildEnvVars(EnvVars env, MavenInstallation mi) throws IOException, InterruptedException { if(mi!=null) { // if somebody has use M2_HOME they will get a classloading error // when M2_HOME points to a different version of Maven2 from // MAVEN_HOME (as Maven 2 gives M2_HOME priority.) // // The other solution would be to set M2_HOME if we are calling Maven2 // and MAVEN_HOME for Maven1 (only of use for strange people that // are calling Maven2 from Maven1) mi.buildEnvVars(env); } // just as a precaution // see http://maven.apache.org/continuum/faqs.html#how-does-continuum-detect-a-successful-build env.put("MAVEN_TERMINATE_CMD","on"); String jvmOptions = env.expand(this.jvmOptions); if(jvmOptions!=null) env.put("MAVEN_OPTS",jvmOptions.replaceAll("[\t\r\n]+"," ")); }
private static void addGitLabBranchBuild(List<GitLabBranchBuild> result, String scmRevisionHash, Set<String> remoteUrls, EnvVars environment, GitLabClient gitLabClient) { for (String remoteUrl : remoteUrls) { try { LOGGER.log(Level.INFO, "Retrieving the gitlab project id from remote url {0}", remoteUrl); final String projectNameWithNameSpace = ProjectIdUtil.retrieveProjectId(gitLabClient, environment.expand(remoteUrl)); if (StringUtils.isNotBlank(projectNameWithNameSpace)) { String projectId = projectNameWithNameSpace; if (projectNameWithNameSpace.contains(".")) { try { projectId = gitLabClient.getProject(projectNameWithNameSpace).getId().toString(); } catch (WebApplicationException | ProcessingException e) { LOGGER.log(Level.SEVERE, String.format("Failed to retrieve projectId for project '%s'", projectNameWithNameSpace), e); } } result.add(new GitLabBranchBuild(projectId, scmRevisionHash)); } } catch (ProjectIdUtil.ProjectIdResolutionException e) { LOGGER.log(Level.WARNING, "Did not match project id in remote url."); } } }
public MavenInstallation forEnvironment(EnvVars environment) { return new MavenInstallation(getName(), environment.expand(getHome()), getProperties().toList()); }
@Override public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) { if (StringUtils.isEmpty(path)) { return null; } try { EnvVars env = build.getEnvironment(listener); String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver()); targetPath = env.expand(targetPath); if (IOUtils.isAbsolute(targetPath)) { return new FilePath(new File(targetPath)); } else { FilePath mrSettings = build.getModuleRoot().child(targetPath); FilePath wsSettings = build.getWorkspace().child(targetPath); try { if (!wsSettings.exists() && mrSettings.exists()) { wsSettings = mrSettings; } } catch (Exception e) { throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote()); } return wsSettings; } } catch (Exception e) { throw new IllegalStateException("failed to prepare global settings.xml"); } }
@Override public FilePath supplySettings(AbstractBuild<?, ?> build, TaskListener listener) { if (StringUtils.isEmpty(path)) { return null; } try { EnvVars env = build.getEnvironment(listener); String targetPath = Util.replaceMacro(this.path, build.getBuildVariableResolver()); targetPath = env.expand(targetPath); if (IOUtils.isAbsolute(targetPath)) { return new FilePath(new File(targetPath)); } else { FilePath mrSettings = build.getModuleRoot().child(targetPath); FilePath wsSettings = build.getWorkspace().child(targetPath); try { if (!wsSettings.exists() && mrSettings.exists()) { wsSettings = mrSettings; } } catch (Exception e) { throw new IllegalStateException("failed to find settings.xml at: " + wsSettings.getRemote()); } return wsSettings; } } catch (Exception e) { throw new IllegalStateException("failed to prepare settings.xml"); } }
@Override public void perform(Run<?,?> build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException { try { listener.getLogger().println(Messages.Fingerprinter_Recording()); Map<String,String> record = new HashMap<String,String>(); EnvVars environment = build.getEnvironment(listener); if(targets.length()!=0) { String expandedTargets = environment.expand(targets); record(build, workspace, listener, record, expandedTargets); } FingerprintAction fingerprintAction = build.getAction(FingerprintAction.class); if (fingerprintAction != null) { fingerprintAction.add(record); } else { build.addAction(new FingerprintAction(build,record)); } if (enableFingerprintsInDependencyGraph) { Jenkins.getInstance().rebuildDependencyGraphAsync(); } } catch (IOException e) { Functions.printStackTrace(e, listener.error(Messages.Fingerprinter_Failed())); build.setResult(Result.FAILURE); } // failing to record fingerprints is an error but not fatal }
String artifacts = build.getEnvironment(listener).expand(this.artifacts);
private String getExpandedName(EnvVars env) { String expandedName = env.expand(name); if (expandedName.length() == 0) { return "**"; } return expandedName; }
public static List<PerformanceReportParser> getParser(Run<?, ?> build, FilePath workspace, PrintStream logger, String glob, EnvVars env, String percentiles) throws IOException, InterruptedException { String expandGlob = env.expand(glob); if (defaultGlobPatterns.containsKey(expandGlob)) { return Collections.singletonList(getParser(defaultGlobPatterns.get(expandGlob), expandGlob, percentiles)); } File path = new File(expandGlob); return path.isAbsolute() ? getParserWithAbsolutePath(build, workspace, logger, path, percentiles) : getParserWithRelativePath(build, workspace, logger, expandGlob, percentiles); }
/** * Overrides all values in the map by the given map. Expressions in values will be expanded. * See {@link #override(String, String)}. * @return {@code this} */ public EnvVars overrideExpandingAll(@Nonnull Map<String,String> all) { for (String key : new OverrideOrderCalculator(this, all).getOrderedVariableNames()) { override(key, expand(all.get(key))); } return this; }
@Override public Proc launch(ProcStarter ps) throws IOException { maskedPrintCommandLine(ps.commands, ps.masks, ps.pwd); EnvVars jobEnv = inherit(ps.envs); // replace variables in command line String[] jobCmd = new String[ps.commands.size()]; for ( int idx = 0 ; idx < jobCmd.length; idx++ ) jobCmd[idx] = jobEnv.expand(ps.commands.get(idx)); return new LocalProc(jobCmd, Util.mapToEnv(jobEnv), ps.stdin, ps.stdout, ps.stderr, toFile(ps.pwd)); }
@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); }
public MercurialInstallation forEnvironment(EnvVars environment) { return new MercurialInstallation(getName(), environment.expand(getHome()), executable, debug, useCaches, useSharing, getProperties().toList()); }
@Override protected Lease decideWorkspace(Node n, WorkspaceList wsl) throws IOException, InterruptedException { String customWorkspace = getProject().getCustomWorkspace(); if (customWorkspace != null) { // we allow custom workspaces to be concurrently used between jobs. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(listener).expand(customWorkspace))); } return super.decideWorkspace(n, wsl); } }
@Override protected Lease decideWorkspace(final Node n, final WorkspaceList wsl) throws InterruptedException, IOException { final Lease baseLease = getParentWorkspaceLease(n, wsl); final FilePath baseDir = baseLease.path; final EnvVars env = getEnvironment(this.listener); env.putAll(getBuildVariables()); final String childWs = getParent().getName(); return Lease.createLinkedDummyLease(baseDir.child(env.expand(childWs)), baseLease); }
protected Lease getParentWorkspaceLease(final Node n, final WorkspaceList wsl) throws InterruptedException, IOException { final DynamicProject mp = getParent().getParent(); final String customWorkspace = mp.getCustomWorkspace(); if (customWorkspace != null) { // we allow custom workspaces to be concurrently used between // jobs. return Lease.createDummyLease(n.getRootPath().child(getEnvironment(this.listener).expand(customWorkspace))); } return wsl.allocate(n.getWorkspaceFor(mp), getParentBuild()); }