use of io.fabric8.openshift.api.model.BuildTriggerPolicyBuilder 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;
}
Aggregations