Search in sources :

Example 21 with AbortException

use of hudson.AbortException in project sonar-scanner-jenkins by SonarSource.

the class SonarRunnerBuilder method perform.

private void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
    if (!SonarInstallation.isValid(getInstallationName(), listener)) {
        throw new AbortException("Invalid SonarQube server installation");
    }
    ArgumentListBuilder args = new ArgumentListBuilder();
    EnvVars env = BuilderUtils.getEnvAndBuildVars(run, listener);
    SonarRunnerInstallation sri = getSonarRunnerInstallation();
    if (sri == null) {
        // No idea if the path contains old sonar-runner or new sonar-scanner, so prefer the new one
        args.add(launcher.isUnix() ? "sonar-scanner" : "sonar-scanner.bat");
    } else {
        sri = BuilderUtils.getBuildTool(sri, env, listener, workspace);
        String exe = sri.getExecutable(launcher);
        if (exe == null) {
            Logger.printFailureMessage(listener);
            String msg = Messages.SonarScanner_ExecutableNotFound(sri.getName());
            listener.fatalError(msg);
            throw new AbortException(msg);
        }
        args.add(exe);
    }
    SonarInstallation sonarInst = getSonarInstallation();
    addTaskArgument(args);
    addAdditionalArguments(args, sonarInst);
    ExtendedArgumentListBuilder argsBuilder = new ExtendedArgumentListBuilder(args, launcher.isUnix());
    populateConfiguration(argsBuilder, run, workspace, listener, env, sonarInst);
    // Java
    computeJdkToUse(run, workspace, listener, env);
    // Java options
    env.put("SONAR_SCANNER_OPTS", getJavaOpts());
    // For backward compatibility with old sonar-runner
    env.put("SONAR_RUNNER_OPTS", getJavaOpts());
    long startTime = System.currentTimeMillis();
    int exitCode;
    try {
        exitCode = executeSonarQubeScanner(run, workspace, launcher, listener, args, env);
    } catch (IOException e) {
        handleErrors(listener, sri, startTime, e);
        exitCode = -1;
    }
    // with workflows, we don't have realtime access to build logs, so url might be null
    // if the analyis doesn't succeed, it will also be null
    SonarUtils.addBuildInfoTo(run, listener, workspace, getSonarInstallation().getName());
    if (exitCode != 0) {
        throw new AbortException("SonarQube scanner exited with non-zero code: " + exitCode);
    }
}
Also used : EnvVars(hudson.EnvVars) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) ArgumentListBuilder(hudson.util.ArgumentListBuilder) ExtendedArgumentListBuilder(hudson.plugins.sonar.utils.ExtendedArgumentListBuilder) IOException(java.io.IOException) AbortException(hudson.AbortException)

Example 22 with AbortException

use of hudson.AbortException in project sonar-scanner-jenkins by SonarSource.

the class SonarRunnerBuilder method perform.

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
    FilePath workspace = build.getWorkspace();
    if (workspace == null) {
        throw new AbortException("no workspace for " + build);
    }
    perform(build, workspace, launcher, listener);
    return true;
}
Also used : FilePath(hudson.FilePath) AbortException(hudson.AbortException)

Example 23 with AbortException

use of hudson.AbortException in project nodejs-plugin by jenkinsci.

the class NodeJSBuildWrapper method setUp.

/*
     * (non-Javadoc)
     * @see jenkins.tasks.SimpleBuildWrapper#setUp(jenkins.tasks.SimpleBuildWrapper.Context, hudson.model.Run, hudson.FilePath, hudson.Launcher, hudson.model.TaskListener, hudson.EnvVars)
     */
@Override
public void setUp(final Context context, Run<?, ?> build, FilePath workspace, Launcher launcher, TaskListener listener, EnvVars initialEnvironment) throws IOException, InterruptedException {
    // get specific installation for the node
    NodeJSInstallation ni = getNodeJS();
    if (ni == null) {
        throw new IOException(Messages.NodeJSBuilders_noInstallationFound(nodeJSInstallationName));
    }
    Computer computer = workspace.toComputer();
    if (computer == null) {
        throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
    }
    Node node = computer.getNode();
    if (node == null) {
        throw new AbortException(Messages.NodeJSBuilders_nodeOffline());
    }
    ni = ni.forNode(node, listener);
    ni = ni.forEnvironment(initialEnvironment);
    String exec = ni.getExecutable(launcher);
    if (exec == null) {
        throw new AbortException(Messages.NodeJSBuilders_noExecutableFound(ni.getHome()));
    }
    ni.buildEnvVars(new EnvVarsAdapter(context));
    EnvVars env = initialEnvironment.overrideAll(context.getEnv());
    // add npmrc config
    if (configId != null) {
        ConfigFile cf = new ConfigFile(configId, null, true);
        FilePath configFile = ConfigFileManager.provisionConfigFile(cf, env, build, workspace, listener, new ArrayList<String>());
        context.env(NodeJSConstants.NPM_USERCONFIG, configFile.getRemote());
        build.addAction(new CleanTempFilesAction(configFile.getRemote()));
    }
}
Also used : NodeJSInstallation(jenkins.plugins.nodejs.tools.NodeJSInstallation) FilePath(hudson.FilePath) EnvVars(hudson.EnvVars) ConfigFile(org.jenkinsci.lib.configprovider.model.ConfigFile) CleanTempFilesAction(org.jenkinsci.plugins.configfiles.common.CleanTempFilesAction) Node(hudson.model.Node) Computer(hudson.model.Computer) IOException(java.io.IOException) AbortException(hudson.AbortException)

Example 24 with AbortException

use of hudson.AbortException in project contrast-continuous-application-security-plugin by jenkinsci.

the class VulnerabilityTrendRecorder method perform.

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, final BuildListener listener) throws IOException {
    if (!build.isBuilding()) {
        return false;
    }
    VulnerabilityTrendHelper.logMessage(listener, "Checking the number of vulnerabilities for this application.");
    ContrastSDK contrastSDK;
    Traces traces;
    Set<Trace> resultTraces = new HashSet<>();
    TeamServerProfile profile = getProfile();
    contrastSDK = VulnerabilityTrendHelper.createSDK(profile.getUsername(), profile.getServiceKey(), profile.getApiKey(), profile.getTeamServerUrl());
    String applicationId = getApplicationId(contrastSDK, profile.getOrgUuid(), build.getParent().getDisplayName());
    if (applicationId.equals("")) {
        VulnerabilityTrendHelper.logMessage(listener, "Application with name '" + build.getParent().getDisplayName() + "' not found.");
        if (profile.isFailOnWrongApplicationName()) {
            throw new AbortException("Application with name '" + build.getParent().getDisplayName() + "' not found.");
        }
    }
    // iterate over conditions; fail on first
    for (ThresholdCondition condition : conditions) {
        VulnerabilityTrendHelper.logMessage(listener, "Checking the threshold condition where " + condition.toString());
        try {
            TraceFilterForm filterForm = new TraceFilterForm();
            filterForm.setAppVersionTags(Collections.singletonList(VulnerabilityTrendHelper.buildAppVersionTag(build)));
            if (condition.getThresholdSeverity() != null) {
                filterForm.setSeverities(VulnerabilityTrendHelper.getSeverityList(condition.getThresholdSeverity()));
            }
            if (condition.getThresholdVulnType() != null) {
                filterForm.setVulnTypes(Collections.singletonList(condition.getThresholdVulnType()));
            }
            traces = contrastSDK.getTracesInOrg(profile.getOrgUuid(), filterForm);
        } catch (Exception e) {
            VulnerabilityTrendHelper.logMessage(listener, e.getMessage());
            throw new AbortException("Unable to retrieve vulnerability information from TeamServer.");
        }
        resultTraces.addAll(traces.getTraces());
        // Integer.parseInt(condition.getThresholdCount());
        int thresholdCount = condition.getThresholdCount();
        if (traces.getCount() > thresholdCount) {
            // save results before failing build
            buildResult(resultTraces, build);
            throw new AbortException("Failed on the threshold condition where " + condition.toString());
        }
    }
    buildResult(resultTraces, build);
    VulnerabilityTrendHelper.logMessage(listener, "This build passes all vulnerability threshold conditions!");
    return true;
}
Also used : Trace(com.contrastsecurity.models.Trace) ContrastSDK(com.contrastsecurity.sdk.ContrastSDK) Traces(com.contrastsecurity.models.Traces) TraceFilterForm(com.contrastsecurity.http.TraceFilterForm) UnauthorizedException(com.contrastsecurity.exceptions.UnauthorizedException) AbortException(hudson.AbortException) IOException(java.io.IOException) HashSet(java.util.HashSet) AbortException(hudson.AbortException)

Example 25 with AbortException

use of hudson.AbortException in project gitea-plugin by jenkinsci.

the class GiteaSCMNavigator method gitea.

private Gitea gitea(SCMSourceOwner owner) throws AbortException {
    GiteaServer server = GiteaServers.get().findServer(serverUrl);
    if (server == null) {
        throw new AbortException("Unknown server: " + serverUrl);
    }
    StandardCredentials credentials = credentials(owner);
    CredentialsProvider.track(owner, credentials);
    return Gitea.server(serverUrl).as(AuthenticationTokens.convert(GiteaAuth.class, credentials));
}
Also used : GiteaServer(org.jenkinsci.plugin.gitea.servers.GiteaServer) StandardCredentials(com.cloudbees.plugins.credentials.common.StandardCredentials) GiteaAuth(org.jenkinsci.plugin.gitea.client.api.GiteaAuth) AbortException(hudson.AbortException)

Aggregations

AbortException (hudson.AbortException)37 IOException (java.io.IOException)13 FilePath (hudson.FilePath)11 EnvVars (hudson.EnvVars)5 ArrayList (java.util.ArrayList)5 Node (hudson.model.Node)4 ArgumentListBuilder (hudson.util.ArgumentListBuilder)4 Launcher (hudson.Launcher)3 Computer (hudson.model.Computer)3 Run (hudson.model.Run)3 WorkspaceList (hudson.slaves.WorkspaceList)3 ServletException (javax.servlet.ServletException)3 StandardCredentials (com.cloudbees.plugins.credentials.common.StandardCredentials)2 AbstractBuild (hudson.model.AbstractBuild)2 ParameterDefinition (hudson.model.ParameterDefinition)2 ParameterValue (hudson.model.ParameterValue)2 PollingResult (hudson.scm.PollingResult)2 SCMRevisionState (hudson.scm.SCMRevisionState)2 File (java.io.File)2 Authentication (org.acegisecurity.Authentication)2