Java Code Examples for hudson.model.AbstractBuild#getWorkspace()

The following examples show how to use hudson.model.AbstractBuild#getWorkspace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JUnitResultArchiverTest.java    From junit-plugin with MIT License 6 votes vote down vote up
@Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    FilePath ws = build.getWorkspace();
    OutputStream os = ws.child(name + ".xml").write();
    try {
        PrintWriter pw = new PrintWriter(os);
        pw.println("<testsuite failures=\"" + fail + "\" errors=\"0\" skipped=\"0\" tests=\"" + (pass + fail) + "\" name=\"" + name + "\">");
        for (int i = 0; i < pass; i++) {
            pw.println("<testcase classname=\"" + name + "\" name=\"passing" + i + "\"/>");
        }
        for (int i = 0; i < fail; i++) {
            pw.println("<testcase classname=\"" + name + "\" name=\"failing" + i + "\"><error message=\"failure\"/></testcase>");
        }
        pw.println("</testsuite>");
        pw.flush();
    } finally {
        os.close();
    }
    new JUnitResultArchiver(name + ".xml").perform(build, ws, launcher, listener);
    return true;
}
 
Example 2
Source File: IssuesRecorder.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
@Override
public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher, final BuildListener listener)
        throws InterruptedException, IOException {
    FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new IOException("No workspace found for " + build);
    }

    perform(build, workspace, listener, new RunResultHandler(build));

    return true;
}
 
Example 3
Source File: ArtifactsSecurity564.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    FilePath f = new FilePath(build.getWorkspace(), path);
    f.mkdirs();
    for (int i = 0; i < numberOfFiles; i++) {
        new FilePath(f, i + ".txt").touch(System.currentTimeMillis());
    }

    return true;
}
 
Example 4
Source File: CreateFileBuilder.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    listener.getLogger().println("Creating a file " + fileName);
    
    FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new AbortException("Cannot get the workspace of the build");
    }
    workspace.child(fileName).write(fileContent, "UTF-8");
    
    return true;
}
 
Example 5
Source File: WorkspaceCopyFileBuilder.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    listener.getLogger().println("Copying a " + fileName + " from " + jobName + "#" + buildNumber);
    
    Jenkins inst = Jenkins.getInstance();
    AbstractProject<?,?> item = inst.getItemByFullName(jobName, AbstractProject.class);
    if (item == null) {
        throw new AbortException("Cannot find a source job: " + jobName);
    }
    
    AbstractBuild<?,?> sourceBuild = item.getBuildByNumber(buildNumber);
    if (sourceBuild == null) {
        throw new AbortException("Cannot find a source build: " + jobName + "#" + buildNumber);
    }
    
    FilePath sourceWorkspace = sourceBuild.getWorkspace();
    if (sourceWorkspace == null) {
        throw new AbortException("Cannot get the source workspace from " + sourceBuild.getDisplayName());
    }
    
    FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new IOException("Cannot get the workspace of the build");
    }
    workspace.child(fileName).copyFrom(sourceWorkspace.child(fileName));
    
    return true;
}
 
Example 6
Source File: DockerRegistryEndpoint.java    From docker-commons-plugin with MIT License 5 votes vote down vote up
/**
 * @deprecated Call {@link #newKeyMaterialFactory(Run, FilePath, Launcher, EnvVars, TaskListener, String)}
 */
@Deprecated
public KeyMaterialFactory newKeyMaterialFactory(@Nonnull AbstractBuild build) throws IOException, InterruptedException {
    final FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new IllegalStateException("Requires workspace.");
    }
    return newKeyMaterialFactory(build.getParent(), workspace.getChannel());
}
 
Example 7
Source File: DockerServerEndpoint.java    From docker-commons-plugin with MIT License 5 votes vote down vote up
/**
 * Makes the key materials available locally for the on-going build
 * and returns {@link KeyMaterialFactory} that gives you the parameters needed to access it.
 *
 * @deprecated Call {@link #newKeyMaterialFactory(Run, VirtualChannel)}
 */
@Deprecated
public KeyMaterialFactory newKeyMaterialFactory(@Nonnull AbstractBuild build) throws IOException, InterruptedException {
    final FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new IllegalStateException("Build has no workspace");
    }
    return newKeyMaterialFactory(build, workspace.getChannel());
}
 
Example 8
Source File: PackerPublisher.java    From packer-plugin with MIT License 5 votes vote down vote up
public FilePath getRemotePath(AbstractBuild build, String... remotePaths) {
    FilePath result = build.getWorkspace();
    for (String remotePath : remotePaths) {
        String path = remotePath.trim();
        if (!path.isEmpty()) {
            result = new FilePath(result, path);
        }
    }
    return result;
}
 
Example 9
Source File: JUnitResultArchiver.java    From junit-plugin with MIT License 5 votes vote down vote up
@Deprecated
protected TestResult parse(String expandedTestResults, AbstractBuild build, Launcher launcher, BuildListener listener)
        throws IOException, InterruptedException
{
    final FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new IllegalArgumentException("The provided build has no workspace");
    }
    return parse(expandedTestResults, build, workspace, launcher, listener);
}
 
Example 10
Source File: TestResultParser.java    From junit-plugin with MIT License 5 votes vote down vote up
@Deprecated
public TestResult parse(String testResultLocations,
                                   AbstractBuild build, Launcher launcher,
                                   TaskListener listener)
        throws InterruptedException, IOException {
    if (Util.isOverridden(TestResultParser.class, getClass(), "parseResult", String.class, Run.class, FilePath.class, Launcher.class, TaskListener.class)) {
        FilePath workspace = build.getWorkspace();
        if (workspace == null) {
            throw new AbortException("no workspace in " + build);
        }
        return parseResult(testResultLocations, build, workspace, launcher, listener);
    } else {
        throw new AbstractMethodError("you must override parseResult");
    }
}
 
Example 11
Source File: WorkspaceFileExporter.java    From DotCi with MIT License 5 votes vote down vote up
private FilePath getFilePath(final AbstractBuild<?, ?> build) {
    final FilePath ws = build.getWorkspace();
    if (ws == null) {
        final Node node = build.getBuiltOn();
        if (node == null) {
            throw new RuntimeException("no such build node: " + build.getBuiltOnStr());
        }
        throw new RuntimeException("no workspace from node " + node + " which is computer " + node.toComputer() + " and has channel " + node.getChannel());
    }
    return ws;
}
 
Example 12
Source File: AnsibleAdHocCommandInvocation.java    From ansible-plugin with Apache License 2.0 4 votes vote down vote up
protected AnsibleAdHocCommandInvocation(String exe, AbstractBuild<?, ?> build, BuildListener listener)
        throws IOException, InterruptedException, AnsibleInvocationException
{
    super(exe, build, build.getWorkspace(), listener);
}
 
Example 13
Source File: AnsiblePlaybookInvocation.java    From ansible-plugin with Apache License 2.0 4 votes vote down vote up
protected AnsiblePlaybookInvocation(String exe, AbstractBuild<?, ?> build, BuildListener listener)
        throws IOException, InterruptedException, AnsibleInvocationException
{
    this(exe, build, build.getWorkspace(), listener);
}
 
Example 14
Source File: CLIRunner.java    From ansible-plugin with Apache License 2.0 4 votes vote down vote up
public CLIRunner(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {
    this.launcher = launcher;
    this.build = build;
    this.listener = listener;
    this.ws = build.getWorkspace();
}
 
Example 15
Source File: ZAProxy.java    From zaproxy-plugin with MIT License 4 votes vote down vote up
/**
 * Start ZAProxy using command line. It uses host and port configured in Jenkins admin mode and
 * ZAProxy program is launched in daemon mode (i.e without UI).
 * ZAProxy is started on the build's machine (so master machine ou slave machine) thanks to 
 * {@link FilePath} object and {@link Launcher} object.
 * 
 * @param build
 * @param listener the listener to display log during the job execution in jenkins
 * @param launcher the object to launch a process locally or remotely
 * @throws InterruptedException 
 * @throws IOException 
 * @throws IllegalArgumentException 
 */
public void startZAP(AbstractBuild<?, ?> build, BuildListener listener, Launcher launcher) 
		throws IllegalArgumentException, IOException, InterruptedException {
	checkParams(build, listener);
	
	FilePath ws = build.getWorkspace();
	if (ws == null) {
		Node node = build.getBuiltOn();
		if (node == null) {
			throw new NullPointerException("no such build node: " + build.getBuiltOnStr());
		}
		throw new NullPointerException("no workspace from node " + node + " which is computer " + node.toComputer() + " and has channel " + node.getChannel());
	}
	
	// Contains the absolute path to ZAP program
	FilePath zapPathWithProgName = new FilePath(ws.getChannel(), zapProgram + getZAPProgramNameWithSeparator(build));
	listener.getLogger().println("Start ZAProxy [" + zapPathWithProgName.getRemote() + "]");
	
	// Command to start ZAProxy with parameters
	List<String> cmd = new ArrayList<String>();
	cmd.add(zapPathWithProgName.getRemote());
	cmd.add(CMD_LINE_DAEMON);
	cmd.add(CMD_LINE_HOST);
	cmd.add(zapProxyHost);
	cmd.add(CMD_LINE_PORT);
	cmd.add(String.valueOf(zapProxyPort));
	cmd.add(CMD_LINE_CONFIG);
	cmd.add(CMD_LINE_API_KEY + "=" + API_KEY);
	
	// Set the default directory used by ZAP if it's defined and if a scan is provided
	if(scanURL && zapDefaultDir != null && !zapDefaultDir.isEmpty()) {
		cmd.add(CMD_LINE_DIR);
		cmd.add(zapDefaultDir);
	}
	
	// Adds command line arguments if it's provided
	if(!cmdLinesZAP.isEmpty()) {
		addZapCmdLine(cmd);
	}
		
	EnvVars envVars = build.getEnvironment(listener);
	// on Windows environment variables are converted to all upper case,
	// but no such conversions are done on Unix, so to make this cross-platform,
	// convert variables to all upper cases.
	for(Map.Entry<String,String> e : build.getBuildVariables().entrySet())
		envVars.put(e.getKey(),e.getValue());
	
	FilePath workDir = new FilePath(ws.getChannel(), zapProgram);
	
	// JDK choice
	computeJdkToUse(build, listener, envVars);
	
	// Launch ZAP process on remote machine (on master if no remote machine)
	launcher.launch().cmds(cmd).envs(envVars).stdout(listener).pwd(workDir).start();
	
	// Call waitForSuccessfulConnectionToZap(int, BuildListener) remotely
	build.getWorkspace().act(new WaitZAProxyInitCallable(this, listener));
}
 
Example 16
Source File: PackerPublisher.java    From packer-plugin with MIT License 4 votes vote down vote up
protected FilePath workingDir(AbstractBuild build, EnvVars env) {
    if (Util.fixEmpty(getChangeDir()) != null) {
        return new FilePath(build.getWorkspace().getChannel(), Util.replaceMacro(getChangeDir(),env));
    }
    return build.getWorkspace();
}