Java Code Examples for hudson.model.AbstractBuild#getBuiltOn()
The following examples show how to use
hudson.model.AbstractBuild#getBuiltOn() .
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: ZAProxy.java From zaproxy-plugin with MIT License | 6 votes |
/** * 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; }
Example 2
Source File: DockerJobProperty.java From docker-plugin with MIT License | 5 votes |
@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); } }
Example 3
Source File: JenkinsUtils.java From docker-plugin with MIT License | 5 votes |
/** * 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(); }
Example 4
Source File: DockerHostTokenMacro.java From docker-plugin with MIT License | 5 votes |
@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; }
Example 5
Source File: WorkspaceFileExporter.java From DotCi with MIT License | 5 votes |
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 6
Source File: ZAProxy.java From zaproxy-plugin with MIT License | 4 votes |
/** * 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)); }