Search in sources :

Example 1 with JenkinsClient

use of net.nemerosa.ontrack.extension.jenkins.client.JenkinsClient in project ontrack by nemerosa.

the class JenkinsJobDecorationExtension method getDecorations.

@Override
public List<Decoration<JenkinsJob>> getDecorations(ProjectEntity entity) {
    // Gets the Jenkins Job property for this entity, if any
    Property<JenkinsJobProperty> property = propertyService.getProperty(entity, JenkinsJobPropertyType.class.getName());
    if (property.isEmpty()) {
        return Collections.emptyList();
    } else {
        // Template branch? Decoration cannot be computed
        if (entity instanceof Branch && ((Branch) entity).getType() == BranchType.TEMPLATE_DEFINITION) {
            return Collections.emptyList();
        }
        // Gets a client
        // FIXME getJob does not need a full HTTP client
        JenkinsClient jenkinsClient = jenkinsClientFactory.getClient(property.getValue().getConfiguration());
        // Gets the Jenkins job
        JenkinsJob job = jenkinsClient.getJob(property.getValue().getJob());
        // Gets the decoration for the job
        return Collections.singletonList(getDecoration(job));
    }
}
Also used : JenkinsJob(net.nemerosa.ontrack.extension.jenkins.client.JenkinsJob) JenkinsClient(net.nemerosa.ontrack.extension.jenkins.client.JenkinsClient)

Example 2 with JenkinsClient

use of net.nemerosa.ontrack.extension.jenkins.client.JenkinsClient in project ontrack by nemerosa.

the class JenkinsServiceTest method before.

@Before
public void before() {
    SecurityService securityService = mock(SecurityService.class);
    configurationRepository = mock(ConfigurationRepository.class);
    encryptionService = mock(EncryptionService.class);
    JenkinsClientFactory jenkinsClientFactory = mock(JenkinsClientFactory.class);
    JenkinsClient okJenkinsClient = mock(JenkinsClient.class);
    when(jenkinsClientFactory.getClient(any(JenkinsConfiguration.class))).thenReturn(okJenkinsClient);
    OntrackConfigProperties ontrackConfigProperties = new OntrackConfigProperties();
    jenkinsService = new JenkinsConfigurationServiceImpl(configurationRepository, securityService, encryptionService, mock(EventPostService.class), mock(EventFactory.class), jenkinsClientFactory, ontrackConfigProperties);
}
Also used : JenkinsClient(net.nemerosa.ontrack.extension.jenkins.client.JenkinsClient) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) EncryptionService(net.nemerosa.ontrack.model.security.EncryptionService) JenkinsConfigurationServiceImpl(net.nemerosa.ontrack.extension.jenkins.JenkinsConfigurationServiceImpl) JenkinsClientFactory(net.nemerosa.ontrack.extension.jenkins.client.JenkinsClientFactory) ConfigurationRepository(net.nemerosa.ontrack.model.support.ConfigurationRepository) OntrackConfigProperties(net.nemerosa.ontrack.model.support.OntrackConfigProperties) JenkinsConfiguration(net.nemerosa.ontrack.extension.jenkins.JenkinsConfiguration) Before(org.junit.Before)

Aggregations

JenkinsClient (net.nemerosa.ontrack.extension.jenkins.client.JenkinsClient)2 JenkinsConfiguration (net.nemerosa.ontrack.extension.jenkins.JenkinsConfiguration)1 JenkinsConfigurationServiceImpl (net.nemerosa.ontrack.extension.jenkins.JenkinsConfigurationServiceImpl)1 JenkinsClientFactory (net.nemerosa.ontrack.extension.jenkins.client.JenkinsClientFactory)1 JenkinsJob (net.nemerosa.ontrack.extension.jenkins.client.JenkinsJob)1 EncryptionService (net.nemerosa.ontrack.model.security.EncryptionService)1 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)1 ConfigurationRepository (net.nemerosa.ontrack.model.support.ConfigurationRepository)1 OntrackConfigProperties (net.nemerosa.ontrack.model.support.OntrackConfigProperties)1 Before (org.junit.Before)1