jenkinsci/docker

I want to replace the "002" in "/kaniko/executor -f ./src/Luck.Walnut.Api/Dockerfile -c . --destination=registry.cn-hangzhou.aliyuncs.com/luck-walunt/walunt-devflow:002" with the values of the parameters BRANCH_NAME and VERSION_NAME, but I have tried several ways such as "$params.BRANCH_NAME", '$params.BRANCH_NAME', '${params.BRANCH_NAME}', etc., and none of them can be recognized correctly. What should I do to correctly replace the value?

KawhiWei opened this issue · 1 comments

Describe your use-case which is not covered by existing documentation.

pipeline {
agent {
kubernetes {
defaultContainer 'jnlp'
yaml """
apiVersion: v1
kind: Pod
metadata:
namespace: luck-infrastructure
spec:
containers:

  • name: jnlp
    image: registry.cn-hangzhou.aliyuncs.com/luck-walunt/inbound-agent:4.10-3-v1
    workingDir: /home/jenkins/agent
    command:
    args:
    tty: true
  • name: docker
    image: registry.cn-hangzhou.aliyuncs.com/luck-walunt/kaniko-executor:v1.9.0-debug-v1
    workingDir: /home/jenkins/agent
    command:
    • cat
      args:
      tty: true
  • name: build
    image: mcr.microsoft.com/dotnet/sdk:6.0
    workingDir: /home/jenkins/agent
    command:
    • sleep
      args:

    • 99d
      tty: true
      """
      }
      }
      parameters {
      string(name: 'BRANCH_NAME', defaultValue: 'main', description: '分支名称')
      string(name: 'VERSION_NAME', defaultValue: 'main', description: '版本号')
      }
      stages{

        stage('拉取代码')
        {
            steps {
                    checkout([
                         $class: 'GitSCM', branches: [[name: "$params.BRANCH_NAME"]],
                         doGenerateSubmoduleConfigurations: false,extensions: [[$class:'CheckoutOption',timeout:30],[$class:'CloneOption',depth:0,noTags:false,reference:'',shallow:false,timeout:3600]], submoduleCfg: [],
                         userRemoteConfigs: [[ url: "https://github.com/KawhiWei/Luck.Walnut.git"]]
                    ])
            }
        }
        stage('编译构建')
        {
            steps {
                    container('docker') {
                        sh '''#!/busybox/sh -e
                           echo '{"auths":{"registry.cn-hangzhou.aliyuncs.com":{"auth":""}}}' > /kaniko/.docker/config.json
                        '''
                        sh '''#!/busybox/sh 
                           /kaniko/executor -f ./src/Luck.Walnut.Api/Dockerfile -c . --destination=registry.cn-hangzhou.aliyuncs.com/luck-walunt/walunt-devflow:002  --insecure --skip-tls-verify -v=debug
                        '''
                    }
            }
        }
        stage('Send HTTP POST Request') {
        steps {
            script {
                def response = httpRequest(
                    url: 'https://www.baidu.com',
                    httpMode: 'GET',
                    timeout: 30,
                    responseHandle: 'NONE'
                )
                if (response.status != 200) {
                    error "Failed to send HTTP POST request: ${response.status} ${response.content}"
                }
                else{
                    echo "Hello, ${response}!"
                }
            }
        }
      

      }
      }
      }

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

@KawhiWei Hello and welcome to the issue tracker of the Jenkins Docker image.

Your issue is related to a pipeline usage issue and not related to the Jenkins Docker image (for controller), so it is out of scope of this repository.
For this reason, I'm going to close this issue as "not planned" because it is not an issue or a request for feature on the official Jenkins Docker image.

I recommend you to open a topic on community.jenkins.io, the community forum to get broader help.

(Tip for your issue: you might be interested in reading carefully https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#string-interpolation . You have to use interpolation of the variable $BRANCH_NAME with one of the methods:

  • Recomended (with simple quotes for the sh pipeline step as you are currently doing):
sh '''#!/busybox/sh 
                     /kaniko/executor -f ./src/Luck.Walnut.Api/Dockerfile -c . --destination=registry.cn-hangzhou.aliyuncs.com/luck-walunt/walunt-devflow:"${BRANCH_NAME}" # ...
  • Or using Groovy interpolation with double quotes (I do not recommend to do this)