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);
}
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());
}
}
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");
}
}
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);
}
}
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();
}
Aggregations