kubernetestfsopenshift

How to pull source codes from TFS for building images in openshift pipeline


I have created one openshift pipeline as follows:

- name: fetch-repository
  taskRef:
    kind: ClusterTask
    name: git-clone
  params:
    - name: URL
      value: $(params.git-url)
    - name: subdirectory
      value: ''
    - name: deleteExisting
      value: 'true'
    - name: revision
      value: $(params.git-revision)
    - name: sslVerify
      value: 'false'  # Disable SSL verification (temporary)
    - name: username
      valueFrom:
       secretKeyRef:
         name: git-secret
         key: username
    - name: password
      valueFrom:
       secretKeyRef:
         name: git-secret
         key: password
  workspaces:
    - name: output
      workspace: shared-workspace

Also created a secret as follows

apiVersion: v1
kind: Secret
metadata:
  name: git-secret
  namespace: my-build-standalone
type: kubernetes.io/basic-auth
stringData:
  username: username
  password: password

But while saving the yaml in the openshift pipeline it shows valueFrom is an unknown field

An error occurred
admission webhook "webhook.pipeline.tekton.dev" denied the request: mutation failed: cannot decode incoming new object: json: unknown field "valueFrom"

any other possibilities to pull source code from TFS?


Solution

  • i have fixed this issue by adding the details in Task

    main pipeline

       apiVersion: tekton.dev/v1
        kind: Pipeline
        metadata:
          name: build-and-deploy
          namespace: my-build-standalone
        spec:
          params:
            - default: ''
              description: Name of the deployment to be created
              name: deployment-name
              type: string
            - default: ''
              description: URL of the TFS repo for the code
              name: git-url
              type: string- default: master
              description: Revision to be used from the repo
              name: git-revision
              type: string
            - default: ''
              description: Image to be built and pushed
              name: IMAGE
              type: string
            - description: Previous image to roll back to (if required)
              name: previous-image
              type: string
          tasks:
            - name: fetch-repository
              params:
                - name: git-url
                  value: $(params.git-url)
                - name: subdirectory
                  value: ''
                - name: deleteExisting
                  value: 'true'
                - name: git-revision
                  value: $(params.git-revision)
                - name: sslVerify
                 value: 'false'
              taskRef:
                kind: Task
                name: git-clone-with-auth
              workspaces:
                - name: output
                  workspace: shared-workspace
            - name: build-image
              params:
                - name: IMAGE
                  value: $(params.IMAGE)
              runAfter:
                - fetch-repository
              taskRef:
                kind: ClusterTask
                name: buildah
              workspaces:
                - name: source
                  workspace: shared-workspace
          workspaces:
            - name: shared-workspace
    

    created a task file as git-clone-with-auth

    apiVersion: tekton.dev/v1
    kind: Task
    metadata:
      name: git-clone-with-auth
      namespace: my-build-standalone
      resourceVersion: '284080763'
      uid: 0cc45b5e-aabe-446f-baec-228fc362195e
    spec:
      params:
        - name: git-url
          type: string
        - name: git-revision
          type: string
      steps:
        - command:
            - /bin/sh
            - '-c'
            - |
              echo "Cloning repository..."
              git config --global credential.helper store
              git config --global http.sslVerify false
              set -e
              # Write credentials
              echo "https://${GIT_USERNAME}:${GIT_PASSWORD}@${FINAL_GIT_URL}" > ~/.git-credentials
              echo "Cloning repository ${GIT_URL} to ${WORKSPACE_PATH}..."
              git clone ${GIT_URL} ${WORKSPACE_PATH}
          computeResources: {}
          env:
            - name: GIT_USERNAME
              valueFrom:
                secretKeyRef:
                  key: username
                  name: git-secret
            - name: GIT_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: git-secret
            - name: GIT_URL
              value: $(params.git-url)
            - name: WORKSPACE_PATH
              value: $(workspaces.output.path)
          image: alpine/git
          name: git-clone
      workspaces:
        - name: output
    

    Now it's working as expected