Since you are using the docker.build method to create a new image from a Dockerfile in the repository during a Pipeline run, you can use the following capability (from the official docs):
It is possible to pass other arguments to docker build by adding them to the second argument of the build() method. When passing arguments this way, the last value in the string must be the path to the docker file, and should end with the folder to use as the build context.
For example:
node {
checkout scm
def dockerfile = 'Dockerfile.test'
def label = 'MyLabel=MyValue'
def customImage = docker.build("my-image:${env.BUILD_ID}",
"--label ${label} -f ${dockerfile} ./dockerfiles")
}
This example builds my-image:${env.BUILD_ID} from the Dockerfile found at /dockerfiles/Dockerfile.test and adds the label MyLabel=MyValue.
Another option you have is Using the LABEL instruction in a the Dockerfile itself:
FROM ubuntu:latest
LABEL version="1.0"
LABEL MyLabel="MyValue"
But this options is a bit less dynamic.