hudson.model.AbstractBuild#getBuiltOn ( )源码实例Demo

下面列出了hudson.model.AbstractBuild#getBuiltOn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: zaproxy-plugin   文件: ZAProxy.java
/**
 * Return the ZAProxy program name with separator prefix (\zap.bat or /zap.sh) depending of the build node and the OS.
 * 
 * @param build
 * @return the ZAProxy program name with separator prefix (\zap.bat or /zap.sh)
 * @throws IOException
 * @throws InterruptedException
 */
private String getZAPProgramNameWithSeparator(AbstractBuild<?, ?> build) throws IOException, InterruptedException {
	Node node = build.getBuiltOn();
	String zapProgramName = "";
	
	// Append zap program following Master/Slave and Windows/Unix
	if( "".equals(node.getNodeName())) { // Master
		if( File.pathSeparatorChar == ':' ) { // UNIX
			zapProgramName = "/" + ZAP_PROG_NAME_SH;
		} else { // Windows (pathSeparatorChar == ';')
			zapProgramName = "\\" + ZAP_PROG_NAME_BAT;
		}
	} 
	else { // Slave
		if( "Unix".equals(((SlaveComputer)node.toComputer()).getOSDescription()) ) {
			zapProgramName = "/" + ZAP_PROG_NAME_SH;
		} else {
			zapProgramName = "\\" + ZAP_PROG_NAME_BAT;
		}
	}
	return zapProgramName;
}
 
源代码2 项目: docker-plugin   文件: DockerJobProperty.java
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    final Node node = build.getBuiltOn();
    if (!(node instanceof DockerTransientNode)) {
        return true;
    }
    DockerTransientNode dockerNode = (DockerTransientNode) node;
    final String containerId = dockerNode.getContainerId();
    final DockerAPI dockerAPI = dockerNode.getDockerAPI();
    try(final DockerClient client = dockerAPI.getClient()) {
        return perform(build, listener, containerId, dockerAPI, client);
    }
}
 
源代码3 项目: docker-plugin   文件: JenkinsUtils.java
/**
 * If the build was on a cloud, get the ID of that cloud.
 */
@Restricted(NoExternalUse.class)
public static Optional<DockerCloud> getCloudForBuild(AbstractBuild build) {
    Node node = build.getBuiltOn();
    if (node instanceof DockerTransientNode) {
        return Optional.of(((DockerTransientNode) node).getCloud());
    }
    return Optional.empty();
}
 
源代码4 项目: docker-plugin   文件: DockerHostTokenMacro.java
@Override
public String evaluate(AbstractBuild<?, ?> abstractBuild, TaskListener taskListener, String s) throws MacroEvaluationException, IOException, InterruptedException {
    Node node = abstractBuild.getBuiltOn();
    if( node instanceof DockerTransientNode) {
        return ((DockerTransientNode) node).getContainerId();
    }

    return null;
}
 
源代码5 项目: DotCi   文件: WorkspaceFileExporter.java
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;
}
 
源代码6 项目: zaproxy-plugin   文件: ZAProxy.java
/**
 * 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));
}