SAP / jenkins-library

Jenkins shared library for Continuous Delivery pipelines.
https://www.project-piper.io
Apache License 2.0
781 stars 594 forks source link

input containerImageName, containerImageTag is not adopted by kubernetesDeploy #4786

Closed TrevorNodeJS closed 7 months ago

TrevorNodeJS commented 9 months ago

There are Three stages enabled in my pipeline:

Acceptance

    def imageTag = params.script.commonPipelineEnvironment.getArtifactVersion()

    kubernetesDeploy(
        script: params.script,
        kubeConfigFileCredentialsId: 'kubeconfig-xman-dev-file',
        deployTool: 'helm3',
        chartPath: 'chart',
        deploymentName: 'tonghe-hello-world',
        helmValues: ['chart/values-xman-dev.yaml'],
        containerImageName: 'tonghe-hello-world',
        containerImageTag: imageTag,
        namespace: 'tonghe-test'
    )

Docker image tonghe-hello-world:1.0.3-20240118093828_8acb8cc6525a0934d22b447865818278994b41f0 is deployed into target cluster successfully.

Promote

    def imageTag = params.script.commonPipelineEnvironment.getArtifactVersion()
    def promotedImageTag = "### cannot determine promoted image tag from $imageTag"

    def pattern = /(\d+\.\d+\.\d+)/
    def matcher = (imageTag =~ pattern)

    if (matcher.find()) {
        promotedImageTag = matcher.group(1)
        matcher = null
        echo "promoted docker image tag is $promotedImageTag"
    } else {
        matcher = null
        throw new Exception("Cannot detemrine promoted docke image tag")
    }

    containerPushToRegistry (
            script: this,
            sourceRegistryUrl: "$containerRegistryUrl",
            sourceImage: "tonghe-hello-world:$imageTag",
            dockerRegistryUrl: "$containerRegistryUrl",
            dockerCredentialsId: 'sirius-common-repositories-cloud-sap',
            sourceCredentialsId: 'sirius-common-repositories-cloud-sap',
            skopeoImage: 'piper.int.repositories.cloud.sap/piper/skopeo',
            dockerImage: "tonghe-hello-world-release:$promotedImageTag"
        )

docker image is push into docker registry: tonghe-hello-world-release:1.0.3

Release

    def imageTag = params.script.commonPipelineEnvironment.getArtifactVersion()
    def promotedImageTag = "### cannot determine promoted image tag from $imageTag"

    def pattern = /(\d+\.\d+\.\d+)/
    def matcher = (imageTag =~ pattern)

    if (matcher.find()) {
        promotedImageTag = matcher.group(1)
        matcher = null
        echo "promoted docker image tag is $promotedImageTag"
    } else {
        matcher = null
        throw new Exception("Cannot detemrine promoted docke image tag")
    }

   kubernetesDeploy(
            script: params.script,
            githubPublishRelease: false,
            kubeConfigFileCredentialsId: 'kubeconfig-xman-master-file',
            deployTool: 'helm3',
            chartPath: 'chart',
            deploymentName: 'tonghe-hello-world',
            helmValues: ['chart/values-xman-master.yaml'],
            namespace: 'tonghe-test',
            containerImageName: 'tonghe-hello-world-release',
            containerImageTag: "$promotedImageTag"
        )

kubernetesDeploy alwayse deploy tonghe-hello-world:1.0.3-20240118093828_8acb8cc6525a0934d22b447865818278994b41f0, instead of promoted docker image tonghe-hello-world-release:1.0.3

for your information, kubernetes can deploy promoted docker image tonghe-hello-world-release:1.0.3 via below input:

        kubernetesDeploy(
            script: params.script,
            githubPublishRelease: false,
            kubeConfigFileCredentialsId: 'kubeconfig-xman-master-file',
            deployTool: 'helm3',
            chartPath: 'chart',
            deploymentName: 'tonghe-hello-world',
            helmValues: ['chart/values-xman-master.yaml'],
            namespace: 'tonghe-test',
            image: "tonghe-hello-world-release:$promotedImageTag",
            imageNames: ['tonghe-hello-world-release'],
            imageNameTags: ["tonghe-hello-world-release:$promotedImageTag"],
            containerImageName: 'tonghe-hello-world-release',
            containerImageTag: "$promotedImageTag"
        )

expectation:

kubernetes can deploy promoted docker image tonghe-hello-world-release:1.0.3 via below input:

   kubernetesDeploy(
            script: params.script,
            githubPublishRelease: false,
            kubeConfigFileCredentialsId: 'kubeconfig-xman-master-file',
            deployTool: 'helm3',
            chartPath: 'chart',
            deploymentName: 'tonghe-hello-world',
            helmValues: ['chart/values-xman-master.yaml'],
            namespace: 'tonghe-test',
            containerImageName: 'tonghe-hello-world-release',
            containerImageTag: "$promotedImageTag"
        )
github-actions[bot] commented 7 months ago

Thank you for your contribution! This issue is stale because it has been open 60 days with no activity. In order to keep it open, please remove stale label or add a comment within the next 10 days. If you need a Piper team member to remove the stale label make sure to add @SAP/jenkins-library-team to your comment.

github-actions[bot] commented 7 months ago

Issue got stale and no further activity happened. It has automatically been closed. Please re-open in case you still consider it relevant.