Search in sources :

Example 1 with JenkinsPipelineBuildStrategy

use of io.fabric8.openshift.api.model.JenkinsPipelineBuildStrategy in project fabric8 by fabric8io.

the class Builds method configureDefaultBuildConfig.

public static BuildConfig configureDefaultBuildConfig(BuildConfig buildConfig, String name, String gitUrl, boolean foundExistingGitUrl, String buildImageStream, String buildImageTag, String s2iCustomBuilderImage, String secret, String jenkinsUrl) {
    BuildConfigSpec spec = buildConfig.getSpec();
    if (spec == null) {
        spec = new BuildConfigSpec();
        buildConfig.setSpec(spec);
    }
    if (!foundExistingGitUrl && Strings.isNotBlank(gitUrl)) {
        BuildSource source = spec.getSource();
        if (source == null) {
            source = new BuildSource();
            spec.setSource(source);
        }
        source.setType("Git");
        GitBuildSource git = source.getGit();
        if (git == null) {
            git = new GitBuildSource();
            source.setGit(git);
        }
        git.setUri(gitUrl);
    }
    if (Strings.isNotBlank(buildImageStream) && Strings.isNotBlank(buildImageTag)) {
        BuildStrategy strategy = spec.getStrategy();
        if (strategy == null) {
            strategy = new BuildStrategy();
            spec.setStrategy(strategy);
        }
        // TODO only do this if we are using Jenkins?
        strategy.setType("JenkinsPipeline");
        JenkinsPipelineBuildStrategy buildStrategy = strategy.getJenkinsPipelineStrategy();
        if (buildStrategy == null) {
            buildStrategy = new JenkinsPipelineBuildStrategy();
            strategy.setJenkinsPipelineStrategy(buildStrategy);
        }
        ListEnvVarBuilder envBuilder = new ListEnvVarBuilder();
        if (Strings.isNotBlank(jenkinsUrl)) {
            envBuilder.withEnvVar("BASE_URI", jenkinsUrl);
        }
        buildStrategy.setJenkinsfilePath("Jenkinsfile");
    }
    List<BuildTriggerPolicy> triggers = spec.getTriggers();
    if (triggers == null) {
        triggers = new ArrayList<>();
    }
    if (triggers.isEmpty()) {
        triggers.add(new BuildTriggerPolicyBuilder().withType("GitHub").withNewGithub().withSecret(secret).endGithub().build());
        triggers.add(new BuildTriggerPolicyBuilder().withType("Generic").withNewGeneric().withSecret(secret).endGeneric().build());
        spec.setTriggers(triggers);
    }
    return buildConfig;
}
Also used : BuildTriggerPolicyBuilder(io.fabric8.openshift.api.model.BuildTriggerPolicyBuilder) BuildSource(io.fabric8.openshift.api.model.BuildSource) GitBuildSource(io.fabric8.openshift.api.model.GitBuildSource) JenkinsPipelineBuildStrategy(io.fabric8.openshift.api.model.JenkinsPipelineBuildStrategy) BuildStrategy(io.fabric8.openshift.api.model.BuildStrategy) JenkinsPipelineBuildStrategy(io.fabric8.openshift.api.model.JenkinsPipelineBuildStrategy) GitBuildSource(io.fabric8.openshift.api.model.GitBuildSource) ListEnvVarBuilder(io.fabric8.kubernetes.api.builders.ListEnvVarBuilder) BuildConfigSpec(io.fabric8.openshift.api.model.BuildConfigSpec) BuildTriggerPolicy(io.fabric8.openshift.api.model.BuildTriggerPolicy)

Aggregations

ListEnvVarBuilder (io.fabric8.kubernetes.api.builders.ListEnvVarBuilder)1 BuildConfigSpec (io.fabric8.openshift.api.model.BuildConfigSpec)1 BuildSource (io.fabric8.openshift.api.model.BuildSource)1 BuildStrategy (io.fabric8.openshift.api.model.BuildStrategy)1 BuildTriggerPolicy (io.fabric8.openshift.api.model.BuildTriggerPolicy)1 BuildTriggerPolicyBuilder (io.fabric8.openshift.api.model.BuildTriggerPolicyBuilder)1 GitBuildSource (io.fabric8.openshift.api.model.GitBuildSource)1 JenkinsPipelineBuildStrategy (io.fabric8.openshift.api.model.JenkinsPipelineBuildStrategy)1