public static Builder createRunSelector(String projectName, String parameters, RunSelector selector, String filter, String excludes, String target, boolean flatten, boolean optional, boolean fingerprintArtifacts, String resultVariableSuffix) { // RunSelector copyArtifact = new RunSelector(projectName); // copyArtifact.setSelector(selectors); // copyArtifact.setOptional(optional); // copyArtifact.setResultVariableSuffix(resultVariableSuffix); // copyArtifact.setVerbose(true); // // copyArtifact.setParameters(parameters); // // copyArtifact.setOperation(null); // copyArtifact.setFilter(filters); // copyArtifact.setExcludes(excludes); // copyArtifact.setTarget(target); // copyArtifact.setFlatten(flatten); // copyArtifact.setFingerprintArtifacts(fingerprintArtifacts); // return copyArtifact; return null; }
private boolean isGradlew (List<Builder> builders) { boolean status = false; if (builders != null && builders.size() > 0 ) { for (Builder builder : builders) { if (builder.getClass().getName().endsWith("Gradle")) { try { Object isUseWrapper = builder.getClass().getMethod("isUseWrapper", null).invoke(builder); if (isUseWrapper instanceof Boolean) { status = ! ((Boolean) isUseWrapper).booleanValue(); LOG.log(Level.FINE, "isGradlew " + !status); } } catch (Exception e) { LOG.log(Level.WARNING, "Exception " + e.getMessage(), e.getCause()); status = false; } } } } return status; }
@Nonnull @Override public Collection<String> getDockerImagesUsedByJob(@Nonnull Job<?,?> job) { if (job instanceof Project) { Project<? extends Project, ? extends Build> project = (Project<?,? extends Build>)job; Set<String> images = new HashSet<String>(); // check DockerHub build step for matching image ID for (Builder b : project.getBuilders()) { if (b instanceof DockerPullImageBuilder) { images.add(((DockerPullImageBuilder)b).getImage()); } } return images; } else { return Collections.emptySet(); } }
/** * Construct and initialize Tcl environment. * <p> * Function overwrites Thread.ClassLoader by Class.ClassLoader due to jenkins dependency loader specific * ( more info - http://jenkins.361315.n4.nabble.com/ClassLoader-in-plugins-td1470791.html ) * </p> * * @param build Related build * @param launcher Build launcher * @param listener Build listener * @throws TclException Error occurred in jtcl or its wrapper */ public TclDriver(AbstractBuild build, Launcher launcher, BuildListener listener, Builder buildInstance) throws TclException { this.build = build; this.buildLauncher = launcher; this.listener = listener; this.builderInstance = buildInstance; // Start init super.Initialize(build.getWorkspace(), getClass().getClassLoader()); super.setIOChannel(new jTclChannel("jTCL_STDERR", jTclChannelType.STDERR, new StdErr())); super.setIOChannel(new jTclChannel("jTCL_STDOUT", jTclChannelType.STDOUT, new StdOut())); // Add resolver commandResolver = new jTclCommandResolver(super.getInterpreter(), JENKINS_NAMESPACE); super.getInterpreter().addInterpResolver("JenkinsResolver", commandResolver); super.getInterpreter().addInterpResolver("Env resolver", new jTclEnvResolver(this, build, listener)); // Add jenkins namespace and resolver Namespace nm = Namespace.createNamespace(super.getInterpreter(), JENKINS_NAMESPACE, null); Namespace.setNamespaceResolver(nm, commandResolver); //TODO: add built-in command handlers }
public DescribableList<Builder, Descriptor<Builder>> getBuildersList( IMode mode) { InheritanceGovernor<DescribableList<Builder, Descriptor<Builder>>> gov = new InheritanceGovernor<DescribableList<Builder, Descriptor<Builder>>>( "buildersList", SELECTOR.BUILDER, this) { @Override protected DescribableList<Builder, Descriptor<Builder>> castToDestinationType(Object o) { return castToDescribableList(o); } @Override public DescribableList<Builder, Descriptor<Builder>> getRawField( InheritanceProject ip) { return ip.getRawBuildersList(); } @Override protected DescribableList<Builder, Descriptor<Builder>> reduceFromFullInheritance( Deque<DescribableList<Builder, Descriptor<Builder>>> list) { return InheritanceGovernor.reduceDescribableByMerge(list); } }; return gov.retrieveFullyDerivedField(this, mode); }
/** * Creates an {@link HttpResponse} that will send a TGZ containing build * scripts. * * @return null, if the file could not be generated, otherwise a valid {@link HttpResponse}. */ public ReadOnlyConfigurationArchive doDownload() { Map<String, Long> versions = (build != null) ? build.getProjectVersions() : null; if (versions != null) { VersionHandler.initVersions(versions); } try { List<Builder> builders = this.getProject().getBuildersList(IMode.INHERIT_FORCED).toList(); try { File archive = this.generateExecutableCompoundScript( builders, this.getProject().getFullName(), this.getBuild().getBuildVariables() ); return new ReadOnlyConfigurationArchive(archive); } catch (IOException ex) { //TODO: Log this error return null; } } finally { VersionHandler.clearVersions(); } }
/** * Get the configured instance for the plugin. * * @param project * @return */ public static NeoLoadPluginOptions getPluginOptions(final AbstractProject<?, ?> project) { final Project<?, ?> proj; NeoBuildAction nba = null; if (!(project instanceof Project)) { return null; } proj = (Project<?, ?>) project; final List<Builder> builders = proj.getBuilders(); for (final Builder b : builders) { if (b instanceof NeoBuildAction) { nba = (NeoBuildAction) b; break; } } return (NeoLoadPluginOptions) nba; }
@Override public Builder newInstance(final StaplerRequest req, final JSONObject data) throws FormException { final ScriptSource source = getScriptSource(req, data); final String scalaName = data.getString("scalaName"); final String params = data.getString("parameters"); final String classpath = data.getString("classPath").trim(); final String scriptParameters = data.getString("scriptParameters"); final boolean debug = data.has("debug"); final boolean suspend; final String port; if(debug) { final JSONObject joDebug = data.getJSONObject("debug"); suspend = joDebug.getBoolean("suspend"); port = joDebug.getString("port"); } else { suspend = false; port = DEFAULT_PORT; } return new ForkedScalaBuilder(scalaName, source, params, classpath, scriptParameters, debug, suspend, port); }
public Collection<? extends Descriptor<?>> getApplicableDescriptors() { // Jenkins.instance.getDescriptorList(SimpleBuildStep) is empty, presumably because that itself is not a Describable. List<Descriptor<?>> r = new ArrayList<>(); populate(r, Builder.class); populate(r, Publisher.class); return r; }
private Builder echoBuilder(final String fileName, final String content) { return new TestBuilder() { @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child(fileName).write(content, "UTF-8"); return true; } }; }
private boolean isBuilderHarcoded (List<Builder> builders) { boolean found = false; if (builders != null && builders.size() > 0 ) { for (Builder builder : builders) { if (builder instanceof hudson.tasks.Shell || builder instanceof hudson.tasks.BatchFile) { if (isHarcoded (((CommandInterpreter)builder).getCommand(), THRESHOLD)) { found = true; } } } } else { found = false; } return found; }
@Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException { // Since the config form lists the optional parameter pathPrefix as // inline, it will be passed through even if stripPathPrefix is false. // This might cause problems if the user, for example, fills in the field // and then unchecks the checkbox. So, explicitly remove pathPrefix // whenever stripPathPrefix is false. if (Boolean.FALSE.equals(formData.remove("stripPathPrefix"))) { formData.remove("pathPrefix"); } return super.newInstance(req, formData); }
@Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (Boolean.FALSE.equals(formData.remove("stripPathPrefix"))) { formData.remove("pathPrefix"); } return super.newInstance(req, formData); }
private static DockerClient createDockerClient(String dockerUrl, String dockerVersion, String dockerCertPath, AuthConfig authConfig) { // TODO JENKINS-26512 SSLConfig dummySSLConf = (new SSLConfig() { public SSLContext getSSLContext() throws KeyManagementException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException { return null; } }); if (dockerCertPath != null) { dummySSLConf = new LocalDirectorySSLConfig(dockerCertPath); } DefaultDockerClientConfig.Builder configBuilder = new DefaultDockerClientConfig.Builder().withDockerHost(dockerUrl) .withApiVersion(dockerVersion).withCustomSslConfig(dummySSLConf); if (authConfig != null) { configBuilder.withRegistryUsername(authConfig.getUsername()) .withRegistryEmail(authConfig.getEmail()) .withRegistryPassword(authConfig.getPassword()) .withRegistryUrl(authConfig.getRegistryAddress()); } // using jaxrs/jersey implementation here (netty impl is also available) DockerCmdExecFactory dockerCmdExecFactory = new DockerCmdExecFactoryImpl() .withConnectTimeout(1000) .withMaxTotalConnections(1) .withMaxPerRouteConnections(1); return DockerClientBuilder.getInstance(configBuilder).withDockerCmdExecFactory(dockerCmdExecFactory).build(); }
public String getSVGDetail() { List<ParameterDefinition> pLst = this.getParameters(IMode.LOCAL_ONLY); if (pLst == null) { return ""; } StringBuilder b = new StringBuilder(); for (ParameterDefinition pd : pLst) { if (pd == null) { continue; } b.append(pd.getName()); ParameterValue pv = pd.getDefaultParameterValue(); if (pv != null && pv instanceof StringParameterValue) { b.append(": "); b.append(((StringParameterValue)pv).value); } b.append('\n'); } if (b.length() > 0) { b.append("\r\n"); } List<Builder> builders = this.getBuilders(); String str = (builders == null || builders.size() != 1) ? "steps" : "step"; int num = (builders == null) ? 0 : builders.size(); b.append(String.format( "%d build %s\n", num, str )); DescribableList<Publisher, Descriptor<Publisher>> pubs = this.getPublishersList(); str = (pubs == null || pubs.size() != 1) ? "publishers" : "publisher"; num = (pubs == null) ? 0 : pubs.size(); b.append(String.format( "%d %s", num, str )); return b.toString(); }
private boolean dumpBuildSteps( List<Builder> builders, List<File> generatedScripts, File srcDir ) throws IOException { boolean isLinux = true; int i = 0; for (Builder builder : builders) { if (!(builder instanceof CommandInterpreter)) { continue; } CommandInterpreter ci = (CommandInterpreter) builder; File builderScript; if (builder instanceof BatchFile) { isLinux = false; builderScript = new File(srcDir, String.format("step_%d.bat", i++)); } else { builderScript = new File(srcDir, String.format("step_%d.sh", i++)); } BufferedWriter out = new BufferedWriter( new FileWriter(builderScript, true) ); String cmd = ci.getCommand(); if (!isLinux) { //Ensure windows line-endings cmd = cmd.replaceAll("\r\n", "\n").replaceAll("\n", "\r\n"); } out.write(cmd); builderScript.setExecutable(true, false); builderScript.setReadable(true, false); builderScript.setWritable(true, false); out.close(); generatedScripts.add(builderScript); } return isLinux; }
/** * Get the configured instance for the plugin. * * @param project * @return */ public static NeoBuildAction getNeoBuildAction(final AbstractProject<?, ?> project) { if (!(project instanceof Project)) { return null; } for (final Builder b : ((Project<?, ?>) project).getBuilders()) { if (b instanceof NeoBuildAction) { return (NeoBuildAction) b; } } return null; }
@Override public Descriptor<Builder> getDescriptor() { final DescriptorImpl descriptor = (DescriptorImpl) super.getDescriptor(); // setting this as an instance allows us to re-select the currently selected dropdown options. descriptor.setNeoBuildAction(this); return descriptor; }
@Override public Builder newInstance(final StaplerRequest req, final JSONObject data) throws FormException { final ScriptSource source = getScriptSource(req, data); final String scalaName = data.getString("scalaName"); final String classpath = data.getString("classPath").trim(); final String scriptParameters = data.getString("scriptParameters"); return new InVmScalaBuilder(scalaName, source, classpath, scriptParameters); }
public WrapperBuilder(Builder builder) { this.builder = builder; }
public Builder getBuilder() { return builder; }
public static Builder createRunSelector(String projectName, String parameters, RunSelector selector, String filter, String target, boolean flatten, boolean optional) { return createRunSelector(projectName, parameters, selector, filter, null, target, flatten, optional, false); }
public static Builder createRunSelector(String projectName, String parameters, RunSelector selector, String filter, String target, boolean flatten, boolean optional, boolean fingerprintArtifacts) { return createRunSelector(projectName, parameters, selector, filter, null, target, flatten, optional, fingerprintArtifacts); }
public static Builder createRunSelector(String projectName, String parameters, RunSelector selector, String filter, String excludes, String target, boolean flatten, boolean optional, boolean fingerprintArtifacts) { return createRunSelector(projectName, parameters, selector, filter, excludes, target, flatten, optional, fingerprintArtifacts, null); }
@Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws Descriptor.FormException { return req.bindJSON(this.clazz, formData); }
@Override public Descriptor<Builder> getDescriptor() { return super.getDescriptor(); }
@Test public void shouldCreateJobWithExtendedDsl() throws Exception { FreeStyleProject job = jenkins.createFreeStyleProject(); job.getBuildersList().add( new ExecuteDslScripts( new ExecuteDslScripts.ScriptLocation( null, null, IOUtils.toString(this .getClass().getClassLoader().getResourceAsStream(JOB_DSL_GROOVY)) ), false, RemovedJobAction.DELETE, RemovedViewAction.DELETE, LookupStrategy.JENKINS_ROOT ) ); jenkins.buildAndAssertSuccess(job); assertThat(jenkins.getInstance().getJobNames(), hasItem(is(JOB_NAME_IN_DSL_SCRIPT))); FreeStyleProject generated = jenkins.getInstance() .getItemByFullName(JOB_NAME_IN_DSL_SCRIPT, FreeStyleProject.class); final DescribableList<Builder, Descriptor<Builder>> builders = generated.getBuildersList(); assertThat("Should have builder", builders, hasSize(1)); assertThat("Should add status builder", builders.get(0), instanceOf(GitHubPRStatusBuilder.class)); assertThat("Should add message", ((GitHubPRStatusBuilder) builders.get(0)).getStatusMessage().getContent(), equalTo(JOB_DSL_BUILDER_TEXT_CONTENT)); verifyPublishers(generated.getPublishersList()); Collection<Trigger<?>> triggers = generated.getTriggers().values(); assertThat("Should add trigger", triggers, hasSize(1)); GitHubPRTrigger trigger = (GitHubPRTrigger) triggers.toArray()[0]; assertThat("Should add trigger of GHPR class", trigger, instanceOf(GitHubPRTrigger.class)); assertThat("Should have pre status", trigger.isPreStatus(), equalTo(true)); assertThat("Should have cancel queued", trigger.isCancelQueued(), equalTo(true)); assertThat("Should set mode", trigger.getTriggerMode(), equalTo(HEAVY_HOOKS_CRON)); final List<GitHubRepoProvider> repoProviders = trigger.getRepoProviders(); assertThat("Should contain repoProvider", repoProviders, notNullValue()); assertThat("Should contain 1 repoProvider", repoProviders, hasSize(1)); final GitHubRepoProvider repoProvider = repoProviders.get(0); assertThat(repoProvider, instanceOf(GitHubPluginRepoProvider.class)); final GitHubPluginRepoProvider provider = (GitHubPluginRepoProvider) repoProvider; assertThat(provider.isCacheConnection(), is(false)); assertThat(provider.isManageHooks(), is(false)); assertThat(provider.getRepoPermission(), is(PUSH)); final List<GitHubPREvent> events = trigger.getEvents(); assertThat("Should add events", events, hasSize(17)); GitHubPREvent event = events.get(15); assertThat(event, instanceOf(GitHubPRNumber.class)); assertThat(((GitHubPRNumber) event).isSkip(), is(false)); assertThat(((GitHubPRNumber) event).isMatch(), is(true)); event = events.get(16); assertThat(event, instanceOf(GitHubPRNumber.class)); assertThat(((GitHubPRNumber) event).isSkip(), is(true)); assertThat(((GitHubPRNumber) event).isMatch(), is(true)); }
public static DescriptorImpl get() { return Builder.all().get(DescriptorImpl.class); }
public AbstractDescriptor(Class<? extends Builder> clazz) { super(clazz); }
@Override public MdtoolBuildStepDescriptor<Builder> getDescriptor() { return (MdtoolBuildStepDescriptor<Builder>) super.getDescriptor(); }
@Override public Builder newInstance(StaplerRequest req, JSONObject formData) throws FormException { return super.newInstance(req, formData); }
private ArrayList<Descriptor<?>> getDescriptors() { ArrayList<Descriptor<?>> r = new ArrayList<Descriptor<?>>(); r.addAll(getClassList(Builder.class)); r.addAll(getClassList(Publisher.class)); return r; }
@Override public List<Builder> getBuilders() { return getParent().getBuilders(); }
@Override public DescribableList<Builder, Descriptor<Builder>> getBuildersList() { return getParent().getBuildersList(); }
@Test public void should_create_plugins_from_build_step_plugins() { Jenkins jenkins = mock(Jenkins.class); ExtensionList extensionList = mock(ExtensionList.class); when(extensionList.iterator()).thenReturn(Lists.newArrayList().iterator()); when(jenkins.getExtensionList(any(Class.class))).thenReturn(extensionList); DescriptorExtensionList<Builder, Descriptor<Builder>> descriptors = mock(DescriptorExtensionList.class); when(jenkins.getDescriptorList(any(Class.class))).thenReturn(descriptors); Descriptor<Builder> buildStepDescriptor = new FakeBuildStepPlugin.FakeDescriptor(); when(descriptors.iterator()).thenReturn(Lists.newArrayList(buildStepDescriptor).iterator()); List<DotCiPluginAdapter> plugins = new DotCiExtensionsHelper(jenkins).createPlugins(Arrays.asList("FakeBuildStepPlugin")); Assert.assertNotNull(plugins); Assert.assertTrue(plugins.get(0) instanceof GenericSimpleBuildStepPlugin); }
@Override public Descriptor<Builder> getDescriptor() { return DESCRIPTOR; }