Skip to main content
added 150 characters in body
Source Link

As I understand you want to add a variable to yourthe docker build commandimage tag,

in this case, you have to get an environment variable from Jenkins and use it in your image label.

pipeline {
    agentpipeline {
    dockerenvironment {
       registry image= 'maven:3-alpine'"docker_hub_account/repository_name"
       registryCredential label= 'my-defined-label-${BUILDS_ALL_TIME}''dockerhub'
        args  '-v /tmp:/tmp'}
   agent }
}any
    stages {
        stage('Example'Building Build'image') {
            steps {
        script {
       sh '#some command'
 docker.build registry + ":$BUILD_NUMBER"
        }
        }
    }
  }
}

pleae use this URL for more info

As I understand you want to add a variable to your docker build command

in this case, you have to get an environment variable from Jenkins and use it in your image label.

pipeline {
    agent {
    docker {
        image 'maven:3-alpine'
        label 'my-defined-label-${BUILDS_ALL_TIME}'
        args  '-v /tmp:/tmp'
    }
}
    stages {
        stage('Example Build') {
            steps {
                sh '#some command'
            }
        }
    }
}

As I understand you want to add a variable to the docker image tag,

in this case, you have to get an environment variable from Jenkins and use it in your image label.

    pipeline {
  environment {
    registry = "docker_hub_account/repository_name"
    registryCredential = 'dockerhub'
  }
  agent any
  stages {
    stage('Building image') {
      steps{
        script {
          docker.build registry + ":$BUILD_NUMBER"
        }
      }
    }
  }
}

pleae use this URL for more info

Source Link

As I understand you want to add a variable to your docker build command

in this case, you have to get an environment variable from Jenkins and use it in your image label.

pipeline {
    agent {
    docker {
        image 'maven:3-alpine'
        label 'my-defined-label-${BUILDS_ALL_TIME}'
        args  '-v /tmp:/tmp'
    }
}
    stages {
        stage('Example Build') {
            steps {
                sh '#some command'
            }
        }
    }
}