user2315104
user2315104

Reputation: 2730

How to define BuildConfig object with Jenkins and openshift

I am using Jenkins and OpenShift to create the build and trigger the deployment. The following is my YAML file :

apiVersion: v1
kind: List
metadata: {}
items:
- apiVersion: v1
  kind: BuildConfig
  metadata:
    name: petclinic-pipeline
  spec:
    source:
      git:
       uri: <<git url>>
      type: Git
    strategy:
      type: JenkinsPipeline
      jenkinsPipelineStrategy:
        jenkinsfilePath: Jenkinsfile
    triggers:
    - generic:
        secret: FiArdDBH
      type: Generic

The Jenkins config is as follows:

node {
  stage('Source Checkout') {
    git url: "git url"
  }

   stage('Build') {
      git url: "git url"
      sh "/var/lib/jenkins/apache-maven-3.5.4/bin/mvn clean package -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=300 -DskipTests=true"
      stash name:"jar", includes:"target/a.jar"
    }

  stage('Build Image') {
    unstash name:"jar"
    sh "oc start-build petclinic-pipeline --from-file=target/a.jar --follow"
  }
 } 

Now, if I apply this, I'm getting the following error :

$ oc start-build petclinic-pipeline --from-file=target/a.jar --follow
Uploading file "target/a.jar" as binary input for the build ... The
Build "petclinic-pipeline-20" is invalid: spec.source.git: Invalid
value: "": must be set when using Jenkins Pipeline strategy with
Jenkinsfile from a git repo

My expectation is that the image should be built and I am not able to understand where the issue is. Is it something like, spec source git should not be used in YAML file when using Jenkins strategy?

Upvotes: 2

Views: 3608

Answers (1)

Daein Park
Daein Park

Reputation: 4703

Personally, I think you had better use the OpenShift Pipeline Jebkins Plugin instead of executing commands for oc start-build.

For example, simple build and deploy description using OpenShift Pipeline Jenkins Plugin. For more details, refer here

apiVersion: v1
kind: BuildConfig
metadata:
  labels:
    name: your-pipeline
  name: your-pipeline
spec:
  runPolicy: Serial
  strategy:
    jenkinsPipelineStrategy:
      jenkinsfile: |-
        node(''){
          stage 'Build using your-yourconfig'
              openshiftBuild(namespace: 'your-project', bldCfg: 'your-buildconfig', showBuildLogs: 'true')
          stage 'Deployment using your-deploymentconfig'
              openshiftDeploy(namespace: 'your-project', depCfg: 'your-deploymentconfig')

        }
    type: JenkinsPipeline
  triggers:
  - github:
      secret: gitsecret
    type: GitHub
  - generic:
      secret: genericsecret
    type: Generic

I hope it help you.

Upvotes: 2

Related Questions