本文整理匯總了Java中jenkins.model.Jenkins類的典型用法代碼示例。如果您正苦於以下問題:Java Jenkins類的具體用法?Java Jenkins怎麽用?Java Jenkins使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Jenkins類屬於jenkins.model包,在下文中一共展示了Jenkins類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doFillCredentialsIdItems
import jenkins.model.Jenkins; //導入依賴的package包/類
/**
* Stapler form completion.
*
* @param serverUrl the server URL.
* @return the available credentials.
*/
@Restricted(NoExternalUse.class) // stapler
@SuppressWarnings("unused")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String serverUrl) {
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
StandardListBoxModel result = new StandardListBoxModel();
serverUrl = GiteaServers.normalizeServerUrl(serverUrl);
result.includeMatchingAs(
ACL.SYSTEM,
Jenkins.getActiveInstance(),
StandardCredentials.class,
URIRequirementBuilder.fromUri(serverUrl).build(),
AuthenticationTokens.matcher(GiteaAuth.class)
);
return result;
}
示例2: setServers
import jenkins.model.Jenkins; //導入依賴的package包/類
/**
* Sets the list of endpoints.
*
* @param servers the list of endpoints.
*/
public synchronized void setServers(@CheckForNull List<? extends GiteaServer> servers) {
Jenkins.getActiveInstance().checkPermission(Jenkins.ADMINISTER);
List<GiteaServer> eps = new ArrayList<>(Util.fixNull(servers));
// remove duplicates and empty urls
Set<String> serverUrls = new HashSet<String>();
for (ListIterator<GiteaServer> iterator = eps.listIterator(); iterator.hasNext(); ) {
GiteaServer endpoint = iterator.next();
String serverUrl = endpoint.getServerUrl();
if (StringUtils.isBlank(serverUrl) || serverUrls.contains(serverUrl)) {
iterator.remove();
continue;
}
serverUrls.add(serverUrl);
}
this.servers = eps;
save();
}
示例3: doFillCredentialsIdItems
import jenkins.model.Jenkins; //導入依賴的package包/類
public static ListBoxModel doFillCredentialsIdItems(String credentialsId) {
if (credentialsId == null) {
credentialsId = "";
}
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
// Important! Otherwise you expose credentials metadata to random
// web requests.
return new StandardListBoxModel()
.includeCurrentValue(credentialsId);
}
return new StandardListBoxModel()
.includeEmptyValue()
.includeAs(ACL.SYSTEM, Jenkins.getInstance(),
OpenShiftTokenCredentials.class)
// .includeAs(ACL.SYSTEM, Jenkins.getInstance(),
// StandardUsernamePasswordCredentials.class)
// .includeAs(ACL.SYSTEM, Jenkins.getInstance(),
// StandardCertificateCredentials.class)
// TODO: Make own type for token or use the existing token
// generator auth type used by sync plugin? or kubernetes?
.includeCurrentValue(credentialsId);
}
示例4: doAutoCompleteBuildJobName
import jenkins.model.Jenkins; //導入依賴的package包/類
/**
* Autocompletion for build job name field
*
* @param value
* - user input for the build job name field
* @return
*/
public AutoCompletionCandidates doAutoCompleteBuildJobName(@QueryParameter String value) {
AutoCompletionCandidates auto = new AutoCompletionCandidates();
// get all jenkins job
List<Job> jobs = Jenkins.getInstance().getAllItems(Job.class);
for (int i = 0; i < jobs.size(); i++) {
String jobName = jobs.get(i).getName();
if (jobName.toLowerCase().startsWith(value.toLowerCase())) {
auto.add(jobName);
}
}
return auto;
}
示例5: buildProxyConfiguration
import jenkins.model.Jenkins; //導入依賴的package包/類
/**
* build proxy for cloud foundry http connection
* @param targetURL - target API URL
* @return the full target URL
*/
private static HttpProxyConfiguration buildProxyConfiguration(URL targetURL) {
ProxyConfiguration proxyConfig = Jenkins.getInstance().proxy;
if (proxyConfig == null) {
return null;
}
String host = targetURL.getHost();
for (Pattern p : proxyConfig.getNoProxyHostPatterns()) {
if (p.matcher(host).matches()) {
return null;
}
}
return new HttpProxyConfiguration(proxyConfig.name, proxyConfig.port);
}
示例6: getTriggeredBuild
import jenkins.model.Jenkins; //導入依賴的package包/類
/**
* locate triggered build
* @param build - the current running build of this job
* @param name - the build job name that you are going to locate
* @param printStream - logger
* @return
*/
public static Run<?,?> getTriggeredBuild(Run build, String name, EnvVars envVars, PrintStream printStream) {
// if user specify the build job as current job or leave it empty
if (name == null || name.isEmpty() || name.equals(build.getParent().getName())) {
printStream.println("[IBM Cloud DevOps] Current job is the build job");
return build;
} else {
name = envVars.expand(name);
Job<?, ?> job = Jenkins.getInstance().getItem(name, getItemGroup(build), Job.class);
if (job != null) {
Run src = getBuild(job, build);
if (src == null) {
// if user runs the test job independently
printStream.println("[IBM Cloud DevOps] Are you running the test job independently? Use the last successful build of the build job");
src = job.getLastSuccessfulBuild();
}
return src;
} else {
// if user does not specify the build job or can not find the build job that user specifies
printStream.println("[IBM Cloud DevOps] ERROR: Failed to find the build job, please check the build job name");
return null;
}
}
}
示例7: doAutoCompleteBuildJobName
import jenkins.model.Jenkins; //導入依賴的package包/類
/**
* Autocompletion for build job name field
* @param value - user input for the build job name field
* @return
*/
public AutoCompletionCandidates doAutoCompleteBuildJobName(@QueryParameter String value) {
AutoCompletionCandidates auto = new AutoCompletionCandidates();
// get all jenkins job
List<Job> jobs = Jenkins.getInstance().getAllItems(Job.class);
HashSet<String> jobSet = new HashSet<>();
for (int i = 0; i < jobs.size(); i++) {
String jobName = jobs.get(i).getName();
if (jobName.toLowerCase().startsWith(value.toLowerCase())) {
jobSet.add(jobName);
}
}
for (String s : jobSet) {
auto.add(s);
}
return auto;
}
示例8: doFillPrincipalCredentialIdItems
import jenkins.model.Jenkins; //導入依賴的package包/類
public ListBoxModel doFillPrincipalCredentialIdItems(
@AncestorInPath Item item,
@QueryParameter String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
if (item == null) {
if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) {
return result.includeCurrentValue(credentialsId);
}
} else {
if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return result.includeCurrentValue(credentialsId);
}
}
List<AzureCredentials> creds = CredentialsProvider.lookupCredentials(AzureCredentials.class, item, ACL.SYSTEM, Collections.<DomainRequirement>emptyList());
for (AzureCredentials cred
:
creds) {
result.add(cred.getId());
}
return result.includeEmptyValue()
.includeCurrentValue(credentialsId);
}
示例9: build
import jenkins.model.Jenkins; //導入依賴的package包/類
@Test public void build() throws Exception {
Maven.MavenInstallation tool = ToolInstallations.configureMaven3();
String name = tool.getName();
Maven.MavenInstallation.DescriptorImpl desc = Jenkins.getInstance().getDescriptorByType(Maven.MavenInstallation.DescriptorImpl.class);
// Defensive - Maven doesn't have a symbol before 2.x, and other tools may still not have symbols after that.
String type = desc.getId();
Set<String> symbols = SymbolLookup.getSymbolValue(desc);
if (!symbols.isEmpty()) {
type = symbols.iterator().next();
}
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + name + "', type: '" + type + "'; def settings = readFile($/$home/conf/settings.xml/$).split(); echo settings[-1]}",
true));
WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0));
r.assertLogContains("</settings>", b);
List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("tool"));
assertThat(coreStepNodes, Matchers.hasSize(1));
assertEquals(name, ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
示例10: toolWithoutSymbol
import jenkins.model.Jenkins; //導入依賴的package包/類
@Test public void toolWithoutSymbol() throws Exception {
File toolHome = folder.newFolder("mockTools");
MockToolWithoutSymbol tool = new MockToolWithoutSymbol("mock-tool-without-symbol", toolHome.getAbsolutePath(), JenkinsRule.NO_PROPERTIES);
Jenkins.getInstance().getDescriptorByType(MockToolWithoutSymbol.MockToolWithoutSymbolDescriptor.class).setInstallations(tool);
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + tool.getName() + "', type: 'mockToolWithoutSymbol'}",
true));
r.assertLogContains("No mockToolWithoutSymbol named mock-tool-without-symbol found",
r.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0)));
p.setDefinition(new CpsFlowDefinition("node {def home = tool name: '" + tool.getName() + "', type: '" + MockToolWithoutSymbol.class.getName() + "'\n"
+ "echo \"${home}\"}",
true));
r.assertLogContains(toolHome.getAbsolutePath(),
r.assertBuildStatusSuccess(p.scheduleBuild2(0)));
}
示例11: doEndOfflineAgentJobs
import jenkins.model.Jenkins; //導入依賴的package包/類
public void doEndOfflineAgentJobs(final StaplerRequest request, final StaplerResponse response) {
Jenkins j;
if ((j = Jenkins.getInstance()) != null) {
Queue queue = j.getQueue();
if (queue != null) {
for (Item job : queue.getItems()) {
if (job.getCauseOfBlockage() instanceof BecauseNodeIsOffline
|| job.getCauseOfBlockage() instanceof BecauseLabelIsOffline) {
queue.cancel(job);
}
}
}
}
try {
response.sendRedirect2(request.getRootPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例12: gatherEnvVarsMaster
import jenkins.model.Jenkins; //導入依賴的package包/類
@Nonnull
private static Map<String, String> gatherEnvVarsMaster(@Nonnull Job<?, ?> job) throws EnvInjectException {
final Jenkins jenkins;
try {
jenkins = Jenkins.getActiveInstance();
} catch(IllegalStateException ex) {
throw new EnvInjectException(ex);
}
EnvVars env = new EnvVars();
env.put("JENKINS_SERVER_COOKIE", Util.getDigestOf("ServerID:" + jenkins.getSecretKey()));
env.put("HUDSON_SERVER_COOKIE", Util.getDigestOf("ServerID:" + jenkins.getSecretKey())); // Legacy compatibility
env.put("JOB_NAME", job.getFullName());
env.put("JENKINS_HOME", jenkins.getRootDir().getPath());
env.put("HUDSON_HOME", jenkins.getRootDir().getPath()); // legacy compatibility
String rootUrl = jenkins.getRootUrl();
if (rootUrl != null) {
env.put("JENKINS_URL", rootUrl);
env.put("HUDSON_URL", rootUrl); // Legacy compatibility
env.put("JOB_URL", rootUrl + job.getUrl());
}
return env;
}
示例13: doFillMirrorgateCredentialsIdItems
import jenkins.model.Jenkins; //導入依賴的package包/類
public ListBoxModel doFillMirrorgateCredentialsIdItems(
@AncestorInPath Item item,
@QueryParameter("mirrorgateCredentialsId") String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
if (item == null) {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
return result.includeCurrentValue(credentialsId);
}
} else if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return result.includeCurrentValue(credentialsId);
}
return result
.includeEmptyValue()
.includeAs(ACL.SYSTEM, item, StandardUsernamePasswordCredentials.class);
}
示例14: doCheckMirrorgateCredentialsId
import jenkins.model.Jenkins; //導入依賴的package包/類
public FormValidation doCheckMirrorgateCredentialsId(
@AncestorInPath Item item,
@QueryParameter("mirrorgateCredentialsId") String credentialsId) {
if (item == null) {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
return FormValidation.ok();
}
} else if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}
if (StringUtils.isBlank(credentialsId)) {
return FormValidation.ok();
}
if (credentialsId.startsWith("${") && credentialsId.endsWith("}")) {
return FormValidation.warning(
"Cannot validate expression based credentials");
}
return FormValidation.ok();
}
示例15: setUp
import jenkins.model.Jenkins; //導入依賴的package包/類
@Before
@Override
public void setUp() {
PowerMockito.mockStatic(Jenkins.class);
PowerMockito.when(Jenkins.getInstance()).thenReturn(jenkins);
PowerMockito.when(jenkins.getDescriptorByType(any()))
.thenReturn(descriptor);
PowerMockito.when(MirrorGateUtils.getMirrorGateAPIUrl())
.thenReturn(MIRRORGATE_URL);
PowerMockito.when(MirrorGateUtils.getUsernamePasswordCredentials())
.thenReturn(null);
PowerMockito.when(MirrorGateUtils.getExtraUrls())
.thenReturn(EXTRA_URL);
when(helper.getMirrorGateService()).thenReturn(service);
}