Search in sources :

Example 31 with AbortException

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

the class MsBuildSQRunnerEnd method perform.

@Override
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException {
    ArgumentListBuilder args = new ArgumentListBuilder();
    EnvVars env = BuilderUtils.getEnvAndBuildVars(run, listener);
    SonarQubeScannerMsBuildParams beginParams = run.getAction(SonarQubeScannerMsBuildParams.class);
    if (beginParams == null) {
        throw new AbortException(Messages.MsBuildScannerEnd_NoBeginStep());
    }
    String scannerName = beginParams.getScannerName();
    String sonarInstName = beginParams.getSqServerName();
    SonarInstallation sonarInstallation = getSonarInstallation(sonarInstName, listener);
    MsBuildSQRunnerInstallation msBuildScanner = Jenkins.getInstance().getDescriptorByType(MsBuildSQRunnerBegin.DescriptorImpl.class).getMsBuildScannerInstallation(scannerName);
    args.add(getExeName(msBuildScanner, env, launcher, listener, workspace));
    addArgs(args, env, sonarInstallation);
    int result = launcher.launch().cmds(args).envs(env).stdout(listener).pwd(BuilderUtils.getModuleRoot(run, workspace)).join();
    if (result != 0) {
        addBadge(run, listener, workspace, sonarInstallation);
        throw new AbortException(Messages.MSBuildScanner_ExecFailed(result));
    }
    addBadge(run, listener, workspace, sonarInstallation);
}
Also used : EnvVars(hudson.EnvVars) ArgumentListBuilder(hudson.util.ArgumentListBuilder) AbortException(hudson.AbortException)

Example 32 with AbortException

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

the class SonarRunnerBuilder method populateConfiguration.

@VisibleForTesting
void populateConfiguration(ExtendedArgumentListBuilder args, Run<?, ?> build, FilePath workspace, TaskListener listener, EnvVars env, @Nullable SonarInstallation si) throws IOException, InterruptedException {
    if (si != null) {
        args.append("sonar.host.url", si.getServerUrl());
        if (StringUtils.isNotBlank(si.getServerAuthenticationToken())) {
            args.appendMasked("sonar.login", si.getServerAuthenticationToken());
        }
    }
    // Project properties
    if (StringUtils.isNotBlank(getProject())) {
        String projectSettingsFile = env.expand(getProject());
        FilePath projectSettingsFilePath = BuilderUtils.getModuleRoot(build, workspace).child(projectSettingsFile);
        if (!projectSettingsFilePath.exists()) {
            // because of the poor choice of getModuleRoot() with CVS/Subversion, people often get confused
            // with where the build file path is relative to. Now it's too late to change this behavior
            // due to compatibility issue, but at least we can make this less painful by looking for errors
            // and diagnosing it nicely. See HUDSON-1782
            // first check if this appears to be a valid relative path from workspace root
            FilePath projectSettingsFilePath2 = workspace.child(projectSettingsFile);
            if (projectSettingsFilePath2.exists()) {
                // This must be what the user meant. Let it continue.
                projectSettingsFilePath = projectSettingsFilePath2;
            } else {
                // neither file exists. So this now really does look like an error.
                String msg = "Unable to find SonarQube project settings at " + projectSettingsFilePath;
                listener.fatalError(msg);
                throw new AbortException(msg);
            }
        }
        args.append("project.settings", projectSettingsFilePath.getRemote());
    }
    // Additional properties
    Properties p = new Properties();
    p.load(new StringReader(env.expand(getProperties())));
    loadProperties(args, p);
    if (!p.containsKey("sonar.projectBaseDir")) {
        FilePath moduleRoot = BuilderUtils.getModuleRoot(build, workspace);
        args.append("sonar.projectBaseDir", moduleRoot.getRemote());
    }
}
Also used : FilePath(hudson.FilePath) StringReader(java.io.StringReader) Properties(java.util.Properties) AbortException(hudson.AbortException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 33 with AbortException

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

the class SonarBuildWrapperTest method failOnInvalidInstallationEnvironment.

@Test
public void failOnInvalidInstallationEnvironment() throws Exception {
    // non existing installation
    BuildListener listener = mock(BuildListener.class);
    when(listener.getLogger()).thenReturn(stream);
    try {
        wrapper.setUp(mock(AbstractBuild.class), mock(Launcher.class), listener);
        fail("Expected exception");
    } catch (AbortException e) {
        assertThat(e).hasMessageContaining("does not match");
    }
}
Also used : BuildListener(hudson.model.BuildListener) AbstractBuild(hudson.model.AbstractBuild) Launcher(hudson.Launcher) AbortException(hudson.AbortException) Test(org.junit.Test)

Example 34 with AbortException

use of hudson.AbortException in project hudson-2.x by hudson.

the class CLICommand method main.

public int main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) {
    this.stdin = new BufferedInputStream(stdin);
    this.stdout = stdout;
    this.stderr = stderr;
    this.locale = locale;
    this.channel = Channel.current();
    registerOptionHandlers();
    CmdLineParser p = new CmdLineParser(this);
    // add options from the authenticator
    SecurityContext sc = SecurityContextHolder.getContext();
    Authentication old = sc.getAuthentication();
    CliAuthenticator authenticator = Hudson.getInstance().getSecurityRealm().createCliAuthenticator(this);
    new ClassParser().parse(authenticator, p);
    try {
        p.parseArgument(args.toArray(new String[args.size()]));
        Authentication auth = authenticator.authenticate();
        if (auth == Hudson.ANONYMOUS)
            auth = loadStoredAuthentication();
        // run the CLI with the right credential
        sc.setAuthentication(auth);
        if (!(this instanceof LoginCommand || this instanceof HelpCommand))
            Hudson.getInstance().checkPermission(Hudson.READ);
        return run();
    } catch (CmdLineException e) {
        stderr.println(e.getMessage());
        printUsage(stderr, p);
        return -1;
    } catch (AbortException e) {
        // signals an error without stack trace
        stderr.println(e.getMessage());
        return -1;
    } catch (Exception e) {
        e.printStackTrace(stderr);
        return -1;
    } finally {
        // restore
        sc.setAuthentication(old);
    }
}
Also used : CliAuthenticator(hudson.security.CliAuthenticator) CmdLineParser(org.kohsuke.args4j.CmdLineParser) BufferedInputStream(java.io.BufferedInputStream) Authentication(org.acegisecurity.Authentication) SecurityContext(org.acegisecurity.context.SecurityContext) CmdLineException(org.kohsuke.args4j.CmdLineException) AbortException(hudson.AbortException) IOException(java.io.IOException) CmdLineException(org.kohsuke.args4j.CmdLineException) ClassParser(org.kohsuke.args4j.ClassParser) AbortException(hudson.AbortException)

Example 35 with AbortException

use of hudson.AbortException in project hudson-2.x by hudson.

the class InstallToolCommand method run.

protected int run() throws Exception {
    Hudson h = Hudson.getInstance();
    h.checkPermission(Hudson.READ);
    // where is this build running?
    BuildIDs id = channel.call(new BuildIDs());
    if (!id.isComplete())
        throw new AbortException("This command can be only invoked from a build executing inside Hudson");
    AbstractProject p = Hudson.getInstance().getItemByFullName(id.job, AbstractProject.class);
    if (p == null)
        throw new AbortException("No such job found: " + id.job);
    p.checkPermission(Item.CONFIGURE);
    List<String> toolTypes = new ArrayList<String>();
    for (ToolDescriptor<?> d : ToolInstallation.all()) {
        toolTypes.add(d.getDisplayName());
        if (d.getDisplayName().equals(toolType)) {
            List<String> toolNames = new ArrayList<String>();
            for (ToolInstallation t : d.getInstallations()) {
                toolNames.add(t.getName());
                if (t.getName().equals(toolName))
                    return install(t, id, p);
            }
            // didn't find the right tool name
            error(toolNames, toolName, "name");
        }
    }
    // didn't find the tool type
    error(toolTypes, toolType, "type");
    // will never be here
    throw new AssertionError();
}
Also used : Hudson(hudson.model.Hudson) ArrayList(java.util.ArrayList) ToolInstallation(hudson.tools.ToolInstallation) AbstractProject(hudson.model.AbstractProject) 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