hudson.util.DescribableList Java Examples

The following examples show how to use hudson.util.DescribableList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractKubernetesPipelineTest.java    From kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@Before
public void configureCloud() throws Exception {
    cloud = setupCloud(this, name);
    createSecret(cloud.connect(), cloud.getNamespace());
    cloud.getTemplates().clear();
    cloud.addTemplate(buildBusyboxTemplate("busybox"));

    setupHost();

    r.jenkins.clouds.add(cloud);

    DescribableList<NodeProperty<?>, NodePropertyDescriptor> list =  r.jenkins.getGlobalNodeProperties();
    EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
    list.add(newEnvVarsNodeProperty);
    EnvVars envVars = newEnvVarsNodeProperty.getEnvVars();
    envVars.put("GLOBAL", "GLOBAL");
    envVars.put("JAVA_HOME_X", "java-home-x");
    r.jenkins.save();
}
 
Example #2
Source File: DescribableListConverter.java    From DotCi with MIT License 6 votes vote down vote up
@Override
public Object decode(Class targetClass, Object fromDBObject, MappedField optionalExtraInfo) {
    if (fromDBObject == null) return null;

    BasicDBList rawList = (BasicDBList) fromDBObject;

    List list = new ArrayList();
    for (Object obj : rawList) {
        DBObject dbObj = (DBObject) obj;
        list.add(getMapper().fromDBObject(optionalExtraInfo.getSubClass(), dbObj, getMapper().createEntityCache()));
    }

    Saveable owner = null; // TODO figure out how to associate the deserialized project here

    return new DescribableList(owner, list);
}
 
Example #3
Source File: BitbucketCloudScmContentProviderTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
private MultiBranchProject mockMbp(String credentialId, User user) {
    MultiBranchProject mbp = mock(MultiBranchProject.class);
    when(mbp.getName()).thenReturn("pipeline1");
    when(mbp.getParent()).thenReturn(j.jenkins);
    BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
    when(scmSource.getServerUrl()).thenReturn(apiUrl);
    when(scmSource.getCredentialsId()).thenReturn(credentialId);
    when(scmSource.getRepoOwner()).thenReturn(USER_UUID);
    when(scmSource.getRepository()).thenReturn("demo1");
    when(mbp.getSCMSources()).thenReturn(Lists.<SCMSource>newArrayList(scmSource));

    //mock blueocean credential provider stuff
    BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
    DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor>(mbp);
    properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(
            user.getId(), credentialId,
            BlueOceanCredentialsProvider.createDomain(apiUrl)
    ));
    Domain domain = mock(Domain.class);
    when(domain.getName()).thenReturn(BitbucketCloudScm.DOMAIN_NAME);
    when(folderProperty.getDomain()).thenReturn(domain);

    when(mbp.getProperties()).thenReturn(properties);
    return mbp;
}
 
Example #4
Source File: BitbucketServerScmContentProviderTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
private MultiBranchProject mockMbp(String credentialId, User user) {
    MultiBranchProject mbp = mock(MultiBranchProject.class);
    when(mbp.getName()).thenReturn("pipeline1");
    when(mbp.getParent()).thenReturn(j.jenkins);
    BitbucketSCMSource scmSource = mock(BitbucketSCMSource.class);
    when(scmSource.getServerUrl()).thenReturn(apiUrl);
    when(scmSource.getCredentialsId()).thenReturn(credentialId);
    when(scmSource.getRepoOwner()).thenReturn("TESTP");
    when(scmSource.getRepository()).thenReturn("pipeline-demo-test");
    when(mbp.getSCMSources()).thenReturn(Lists.<SCMSource>newArrayList(scmSource));

    //mock blueocean credential provider stuff
    BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
    DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> properties = new DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor>(mbp);
    properties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(
            user.getId(), credentialId,
            BlueOceanCredentialsProvider.createDomain(apiUrl)
    ));
    Domain domain = mock(Domain.class);
    when(domain.getName()).thenReturn(BitbucketServerScm.DOMAIN_NAME);
    when(folderProperty.getDomain()).thenReturn(domain);

    when(mbp.getProperties()).thenReturn(properties);
    return mbp;
}
 
Example #5
Source File: RepairnatorPostBuild.java    From repairnator with MIT License 6 votes vote down vote up
public void createGlobalEnvironmentVariables(String key, String value){

        Jenkins instance = Jenkins.getInstance();

        DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = instance.getGlobalNodeProperties();
        List<EnvironmentVariablesNodeProperty> envVarsNodePropertyList = globalNodeProperties.getAll(EnvironmentVariablesNodeProperty.class);

        EnvironmentVariablesNodeProperty newEnvVarsNodeProperty = null;
        EnvVars envVars = null;

        if ( envVarsNodePropertyList == null || envVarsNodePropertyList.size() == 0 ) {
            newEnvVarsNodeProperty = new hudson.slaves.EnvironmentVariablesNodeProperty();
            globalNodeProperties.add(newEnvVarsNodeProperty);
            envVars = newEnvVarsNodeProperty.getEnvVars();
        } else {
            envVars = envVarsNodePropertyList.get(0).getEnvVars();
        }
        envVars.put(key, value);
        try {
            instance.save();
        } catch(Exception e) {
            System.out.println("Failed to create env variable");
        }
    }
 
Example #6
Source File: GithubIssueTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void changeSetEntryIsNotGithub() throws Exception {
    MultiBranchProject project = mock(MultiBranchProject.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);

    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);

    when(entry.getMsg()).thenReturn("Closed #123 #124");
    when(project.getSCMSources()).thenReturn(Lists.newArrayList(new GitSCMSource("http://example.com/repo.git")));

    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(0, resolved.size());
}
 
Example #7
Source File: GithubIssueTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void changeSetJobParentNotMultibranch() throws Exception {
    AbstractFolder project = mock(AbstractFolder.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);

    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);

    when(entry.getMsg()).thenReturn("Closed #123 #124");

    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(0, resolved.size());
}
 
Example #8
Source File: GithubMockBase.java    From blueocean-plugin with MIT License 6 votes vote down vote up
protected MultiBranchProject mockMbp(String credentialId,User user, String credentialDomainName){
    MultiBranchProject mbp = mock(MultiBranchProject.class);
    when(mbp.getName()).thenReturn("PR-demo");
    when(mbp.getParent()).thenReturn(j.jenkins);
    GitHubSCMSource scmSource = mock(GitHubSCMSource.class);
    when(scmSource.getApiUri()).thenReturn(githubApiUrl);
    when(scmSource.getCredentialsId()).thenReturn(credentialId);
    when(scmSource.getRepoOwner()).thenReturn("cloudbeers");
    when(scmSource.getRepository()).thenReturn("PR-demo");
    when(mbp.getSCMSources()).thenReturn(Lists.<SCMSource>newArrayList(scmSource));
    BlueOceanCredentialsProvider.FolderPropertyImpl folderProperty = mock(BlueOceanCredentialsProvider.FolderPropertyImpl.class);
    DescribableList<AbstractFolderProperty<?>,AbstractFolderPropertyDescriptor> mbpProperties = new DescribableList<AbstractFolderProperty<?>,AbstractFolderPropertyDescriptor>(mbp);
    mbpProperties.add(new BlueOceanCredentialsProvider.FolderPropertyImpl(
            user.getId(), credentialId,
            BlueOceanCredentialsProvider.createDomain(githubApiUrl)
    ));
    Domain domain = mock(Domain.class);
    when(domain.getName()).thenReturn(credentialDomainName);
    when(folderProperty.getDomain()).thenReturn(domain);
    when(mbp.getProperties()).thenReturn(mbpProperties);
    return mbp;
}
 
Example #9
Source File: FolderVaultConfigurationSpec.java    From hashicorp-vault-plugin with MIT License 6 votes vote down vote up
@Test
public void resolverShouldCorrectlyMerge() {
    final DescribableList firstFolderProperties = mock(DescribableList.class);
    when(firstFolderProperties.get(FolderVaultConfiguration.class))
        .thenReturn(completeTestConfigFolder("firstParent", null));

    final DescribableList secondFolderProperties = mock(DescribableList.class);
    when(secondFolderProperties.get(FolderVaultConfiguration.class))
        .thenReturn(completeTestConfigFolder("secondParent", 2));

    final AbstractFolder secondParent = generateMockFolder(secondFolderProperties, null);

    final AbstractFolder firstParent = generateMockFolder(firstFolderProperties, secondParent);

    final Job job = generateMockJob(firstParent);

    VaultConfiguration result = new FolderVaultConfiguration.ForJob().forJob(job);

    VaultConfiguration expected = completeTestConfig("firstParent", null)
        .mergeWithParent(completeTestConfig("secondParent", 2));

    assertThat(result.getVaultCredentialId(), is(expected.getVaultCredentialId()));
    assertThat(result.getVaultUrl(), is(expected.getVaultUrl()));
    assertThat(result.getEngineVersion(), is(expected.getEngineVersion()));
}
 
Example #10
Source File: KubernetesTest.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
@Test
@LocalData()
public void upgradeFrom_0_10() throws Exception {
    List<PodTemplate> templates = cloud.getTemplates();
    PodTemplate template = templates.get(0);
    DescribableList<NodeProperty<?>,NodePropertyDescriptor> nodeProperties = template.getNodeProperties();
    assertEquals(1, nodeProperties.size());
    ToolLocationNodeProperty property = (ToolLocationNodeProperty) nodeProperties.get(0);
    assertEquals(1, property.getLocations().size());
    ToolLocation location = property.getLocations().get(0);
    assertEquals("Default", location.getName());
    assertEquals("/custom/path", location.getHome());
    assertEquals(GitTool.class, location.getType().clazz);
    assertEquals(cloud.DEFAULT_WAIT_FOR_POD_SEC, cloud.getWaitForPodSec());
}
 
Example #11
Source File: JUnitResultArchiver.java    From junit-plugin with MIT License 5 votes vote down vote up
@Deprecated
public JUnitResultArchiver(
        String testResults,
        boolean keepLongStdio,
        DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers,
        double healthScaleFactor) {
    this.testResults = testResults;
    setKeepLongStdio(keepLongStdio);
    setTestDataPublishers(testDataPublishers == null ? Collections.<TestDataPublisher>emptyList() : testDataPublishers);
    setHealthScaleFactor(healthScaleFactor);
    setAllowEmptyResults(false);
}
 
Example #12
Source File: JobDslITest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a freestyle job from a YAML file and verifies that issue recorder finds warnings.
 */
@Test
public void shouldCreateFreestyleJobUsingJobDslAndVerifyIssueRecorderWithDefaultConfiguration() {
    configureJenkins("job-dsl-warnings-ng-default.yaml");

    TopLevelItem project = getJenkins().jenkins.getItem("dsl-freestyle-job");

    assertThat(project).isNotNull();
    assertThat(project).isInstanceOf(FreeStyleProject.class);

    DescribableList<Publisher, Descriptor<Publisher>> publishers = ((FreeStyleProject) project).getPublishersList();
    assertThat(publishers).hasSize(1);

    Publisher publisher = publishers.get(0);
    assertThat(publisher).isInstanceOf(IssuesRecorder.class);

    HealthReport healthReport = ((FreeStyleProject) project).getBuildHealth();
    assertThat(healthReport.getScore()).isEqualTo(100);

    IssuesRecorder recorder = (IssuesRecorder) publisher;

    assertThat(recorder.getAggregatingResults()).isFalse();
    assertThat(recorder.getTrendChartType()).isEqualTo(TrendChartType.AGGREGATION_TOOLS);
    assertThat(recorder.getBlameDisabled()).isFalse();
    assertThat(recorder.getForensicsDisabled()).isFalse();
    assertThat(recorder.getEnabledForFailure()).isFalse();
    assertThat(recorder.getHealthy()).isEqualTo(0);
    assertThat(recorder.getId()).isNull();
    assertThat(recorder.getIgnoreFailedBuilds()).isTrue();
    assertThat(recorder.getIgnoreQualityGate()).isFalse();
    assertThat(recorder.getMinimumSeverity()).isEqualTo("LOW");
    assertThat(recorder.getName()).isNull();
    assertThat(recorder.getQualityGates()).hasSize(0);
    assertThat(recorder.getSourceCodeEncoding()).isEmpty();
    assertThat(recorder.getUnhealthy()).isEqualTo(0);

    List<Tool> tools = recorder.getTools();
    assertThat(tools).hasSize(2);
    assertThat(tools.get(0)).isInstanceOf(Java.class);
}
 
Example #13
Source File: DescribableListConverter.java    From DotCi with MIT License 5 votes vote down vote up
@Override
public Object encode(Object value, MappedField optionalExtraInfo) {
    if (value == null) return null;

    DescribableList describableList = (DescribableList) value;

    BasicDBList convertedList = new BasicDBList();

    for (Object obj : describableList.toList()) {
        convertedList.add(getMapper().toDBObject(obj));
    }

    return convertedList;
}
 
Example #14
Source File: JUnitResultArchiver.java    From junit-plugin with MIT License 5 votes vote down vote up
@Deprecated
public JUnitResultArchiver(
        String testResults,
        boolean keepLongStdio,
        DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers) {
    this(testResults, keepLongStdio, testDataPublishers, 1.0);
}
 
Example #15
Source File: FolderVaultConfigurationSpec.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
private AbstractFolder generateMockFolder(final DescribableList firstFolderProperties,
    final AbstractFolder parentToReturn) {
    return new AbstractFolder<TopLevelItem>(null, null) {
        @NonNull
        @Override
        public ItemGroup getParent() {
            return parentToReturn;
        }

        @Override
        public DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> getProperties() {
            return firstFolderProperties;
        }
    };
}
 
Example #16
Source File: DslIntegrationTest.java    From github-integration-plugin with MIT License 5 votes vote down vote up
private void verifyPublishers(DescribableList<Publisher, Descriptor<Publisher>> publishers) {
    assertThat("Should add publisher", publishers, hasSize(2));

    assertThat("Should add status publisher", publishers.get(0), instanceOf(GitHubPRBuildStatusPublisher.class));
    assertThat("Should add 2 packages",
            ((GitHubPRBuildStatusPublisher) publishers.get(0)).getStatusMsg().getContent(),
            equalTo(JOB_DSL_PUBLISHER_TEXT_CONTENT));

    assertThat("Has comment publisher", publishers.get(1), instanceOf(GitHubPRCommentPublisher.class));
    GitHubPRCommentPublisher commentPublisher = (GitHubPRCommentPublisher) publishers.get(1);

    assertThat("Comment matches", commentPublisher.getComment().getContent(), equalTo("comment"));
    assertThat("Only failed builds", commentPublisher.getStatusVerifier().getBuildStatus(), equalTo(Result.FAILURE));
    assertThat("Publish marked as failure", commentPublisher.getErrorHandler().getBuildStatus(), equalTo(Result.FAILURE));
}
 
Example #17
Source File: GithubIssueTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void changeSetEntry() throws Exception {
    MultiBranchProject project = mock(MultiBranchProject.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);

    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);

    GitHubSCMSource source = new GitHubSCMSource("foo", null, null, null, "example", "repo");
    when(project.getSCMSources()).thenReturn(Lists.newArrayList(source));

    when(entry.getMsg()).thenReturn("Closed #123 #124");

    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(2, resolved.size());

    Map<String, BlueIssue> issueMap = Maps.uniqueIndex(resolved, new Function<BlueIssue, String>() {
        @Override
        public String apply(BlueIssue input) {
            return input.getId();
        }
    });

    BlueIssue issue123 = issueMap.get("#123");
    Assert.assertEquals("https://github.com/example/repo/issues/123", issue123.getURL());

    BlueIssue issue124 = issueMap.get("#124");
    Assert.assertEquals("https://github.com/example/repo/issues/124", issue124.getURL());
}
 
Example #18
Source File: JenkinsConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@ConfiguredWithCode("ConfigureLabels.yml")
public void shouldExportLabelAtoms() throws Exception {
    DescribableList properties = Jenkins.get().getLabelAtom("label1").getProperties();
    properties.add(new TestProperty(1));

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    ConfigurationAsCode.get().export(out);
    final String exported = out.toString();

    String content = FileUtils.readFileToString(new File(getClass().getResource("ExpectedLabelsConfiguration.yml").toURI()), "UTF-8");
    assertThat(exported, containsString(content));
}
 
Example #19
Source File: JenkinsConfiguratorTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
@Issue("Issue #173")
@ConfiguredWithCode("SetEnvironmentVariable.yml")
public void shouldSetEnvironmentVariable() throws Exception {
    final DescribableList<NodeProperty<?>, NodePropertyDescriptor> properties = Jenkins.get().getNodeProperties();
    EnvVars env = new EnvVars();
    for (NodeProperty<?> property : properties) {
        property.buildEnvVars(env, TaskListener.NULL);
    }
    assertEquals("BAR", env.get("FOO"));
}
 
Example #20
Source File: GlobalNodePropertiesTest.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
@Test
public void configure() throws Exception {
    final Jenkins jenkins = Jenkins.get();

    DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = jenkins.getGlobalNodeProperties();

    Set<Map.Entry<String, String>> entries = ((EnvironmentVariablesNodeProperty) nodeProperties.get(0)).getEnvVars().entrySet();
    assertEquals(1, entries.size());

    Map.Entry<String, String> envVar = entries.iterator().next();
    assertEquals("FOO", envVar.getKey());
    assertEquals("BAR", envVar.getValue());
}
 
Example #21
Source File: BaseConfigurator.java    From configuration-as-code-plugin with MIT License 5 votes vote down vote up
protected Attribute createAttribute(String name, final TypePair type) {

        boolean multiple =
                type.rawType.isArray()
            ||  Collection.class.isAssignableFrom(type.rawType);

        // If attribute is a Collection|Array of T, we need to introspect further to determine T
        Class c = multiple ? getComponentType(type) : type.rawType;
        if (c == null) {
            throw new IllegalStateException("Unable to detect type of attribute " + getTarget() + '#' + name);
        }

        // special collection types with dedicated handlers to manage data replacement / possible values
        if (DescribableList.class.isAssignableFrom(type.rawType)) {
            return new DescribableListAttribute(name, c);
        } else if (PersistedList.class.isAssignableFrom(type.rawType)) {
            return new PersistedListAttribute(name, c);
        }

        Attribute attribute;
        if (!c.isPrimitive() && !c.isEnum() && Modifier.isAbstract(c.getModifiers())) {
            if (!Describable.class.isAssignableFrom(c)) {
                // Not a Describable, so we don't know how to detect concrete implementation type
                LOGGER.warning("Can't handle "+getTarget()+"#"+name+": type is abstract but not Describable.");
                return null;
            }
            attribute = new DescribableAttribute(name, c);
        } else {
            attribute = new Attribute(name, c);
        }

        attribute.multiple(multiple);

        return attribute;
    }
 
Example #22
Source File: IntegrationTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the issue recorder instance for the specified job.
 *
 * @param job
 *         the job to get the recorder for
 *
 * @return the issue recorder
 */
protected IssuesRecorder getRecorder(final AbstractProject<?, ?> job) {
    DescribableList<Publisher, Descriptor<Publisher>> publishers = job.getPublishersList();
    for (Publisher publisher : publishers) {
        if (publisher instanceof IssuesRecorder) {
            return (IssuesRecorder) publisher;
        }
    }
    throw new AssertionError("No instance of IssuesRecorder found for job " + job);
}
 
Example #23
Source File: JUnitResultArchiver.java    From junit-plugin with MIT License 4 votes vote down vote up
@Deprecated
public JUnitResultArchiver(String testResults,
        DescribableList<TestDataPublisher, Descriptor<TestDataPublisher>> testDataPublishers) {
    this(testResults, false, testDataPublishers);
}
 
Example #24
Source File: DynamicSubProject.java    From DotCi with MIT License 4 votes vote down vote up
@Override
public DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList() {
    return getParent().getBuildWrappersList();
}
 
Example #25
Source File: DescribableListConverter.java    From DotCi with MIT License 4 votes vote down vote up
public DescribableListConverter() {
    super(DescribableList.class);
}
 
Example #26
Source File: DynamicSubProject.java    From DotCi with MIT License 4 votes vote down vote up
@Override
public DescribableList<Builder, Descriptor<Builder>> getBuildersList() {
    return getParent().getBuildersList();
}
 
Example #27
Source File: JiraExtBuildStep.java    From jira-ext-plugin with Apache License 2.0 4 votes vote down vote up
@DataBoundConstructor
public JiraExtBuildStep(IssueStrategyExtension issueStrategy, List<JiraOperationExtension> extensions)
{
    this.issueStrategy = issueStrategy;
    this.extensions = new DescribableList<>(Saveable.NOOP, Util.fixNull(extensions));
}
 
Example #28
Source File: JcascTest.java    From git-client-plugin with MIT License 4 votes vote down vote up
@Override
protected void assertConfiguredAsExpected(RestartableJenkinsRule restartableJenkinsRule, String s) {
    final ToolDescriptor descriptor = (ToolDescriptor) restartableJenkinsRule.j.jenkins.getDescriptor(GitTool.class);
    final ToolInstallation[] installations = descriptor.getInstallations();
    assertThat(installations, arrayWithSize(4));
    assertThat(installations, arrayContainingInAnyOrder(
            allOf(
                    instanceOf(JGitTool.class),
                    hasProperty("name", equalTo(JGitTool.MAGIC_EXENAME))
            ),
            allOf(
                    instanceOf(JGitApacheTool.class),
                    hasProperty("name", equalTo(JGitApacheTool.MAGIC_EXENAME))
            ),
            allOf(
                    instanceOf(GitTool.class),
                    not(instanceOf(JGitTool.class)),
                    not(instanceOf(JGitApacheTool.class)),
                    hasProperty("name", equalTo("Default")),
                    hasProperty("home", equalTo("git"))
            ),
            allOf(
                    instanceOf(GitTool.class),
                    not(instanceOf(JGitTool.class)),
                    not(instanceOf(JGitApacheTool.class)),
                    hasProperty("name", equalTo("optional")),
                    hasProperty("home", equalTo("/opt/git/git"))
            ))
    );
    final DescribableList<ToolProperty<?>, ToolPropertyDescriptor> properties = Arrays.stream(installations).filter(t -> t.getName().equals("optional")).findFirst().get().getProperties();
    assertThat(properties, iterableWithSize(1));
    final ToolProperty<?> property = properties.get(0);
    assertThat(property, instanceOf(InstallSourceProperty.class));
    assertThat(((InstallSourceProperty)property).installers,
            containsInAnyOrder(
                    allOf(
                            instanceOf(BatchCommandInstaller.class),
                            hasProperty("command", equalTo("echo \"got git\""))
                    ),
                    allOf(
                            instanceOf(ZipExtractionInstaller.class),
                            hasProperty("url", equalTo("file://some/path.zip"))
                    )
            )
    );
}
 
Example #29
Source File: DslIntegrationTest.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@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));
}
 
Example #30
Source File: ContainerStepExecution.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public boolean start() throws Exception {
    LOGGER.log(Level.FINE, "Starting container step.");
    String containerName = step.getName();
    String shell = step.getShell();

    KubernetesNodeContext nodeContext = new KubernetesNodeContext(getContext());

    EnvironmentExpander env = getContext().get(EnvironmentExpander.class);
    EnvVars globalVars = null;
    Jenkins instance = Jenkins.getInstance();

    DescribableList<NodeProperty<?>, NodePropertyDescriptor> globalNodeProperties = instance.getGlobalNodeProperties();
    List<EnvironmentVariablesNodeProperty> envVarsNodePropertyList = globalNodeProperties
            .getAll(EnvironmentVariablesNodeProperty.class);
    if (envVarsNodePropertyList != null && envVarsNodePropertyList.size() != 0) {
        globalVars = envVarsNodePropertyList.get(0).getEnvVars();
    }

    EnvVars rcEnvVars = null;
    Run run = getContext().get(Run.class);
    TaskListener taskListener = getContext().get(TaskListener.class);
    if(run!=null && taskListener != null) {
        rcEnvVars = run.getEnvironment(taskListener);
    }

    decorator = new ContainerExecDecorator();
    decorator.setNodeContext(nodeContext);
    decorator.setContainerName(containerName);
    decorator.setEnvironmentExpander(env);
    decorator.setWs(getContext().get(FilePath.class));
    decorator.setGlobalVars(globalVars);
    decorator.setRunContextEnvVars(rcEnvVars);
    decorator.setShell(shell);
    getContext().newBodyInvoker()
            .withContext(BodyInvoker
                    .mergeLauncherDecorators(getContext().get(LauncherDecorator.class), decorator))
            .withCallback(new ContainerExecCallback(decorator))
            .start();
    return false;
}