Jenkins Dockerfile declarative pipelines: getting the built image tag I'm trying to get the image tag generated with the help of the dockerfile agent in Jenkins declarative pipelines.

This Jenkinsfile is incomplete though, because I still need the deployment steps.

Normally, people would then want a step to push to Dockerhub. Although I don't even know how to do that, I want something different: I want to re-tag the built image locally to a name of my choice. This is because this is a hobby project, and my Jenkins and production servers are the same. The problem is that I don't know how to get the dynamically generated image ID for the docker tag command.

(Then what would come next is to swap out the old running image with the new one, but I could probably take care of that myself.)

Here is my Jenkinsfile:

pipeline {
    agent {
        dockerfile {
            args '--network szeremi -e DB_HOST=mysql -e APP_ENV=testing'
        }
    }

    stages {
        stage('Run tests') {
            steps {
                sh 'cd /var/www &amp;&amp; php artisan migrate:fresh &amp;&amp; vendor/bin/phpunit'
            }
        }
    }
}


Please help me use Jenkins declarative pipelines to re-tag my built-by-dockerfile image.
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