Passing Jenkins pipeline parameters to a Dockerfile can be achieved by using the ARG instruction in the Dockerfile and passing the values from the Jenkins pipeline when building the Docker image. 

Lets see how to do it:

1. Define the Parameter in Jenkins Pipeline:

First, define the parameter in your Jenkins pipeline. You can do this in the Jenkinsfile:
Jenkins Pipeline (Jenkinsfile)

pipeline {
    agent any
    parameters {
        string(name: 'APP_VERSION', defaultValue: '1.0.0', description: 'Application Version')
    }
    stages {
        stage('Build Docker Image') {
            steps {
                script {
                    def appVersion = params.APP_VERSION
                    sh "docker build --build-arg APP_VERSION=${appVersion} -t myapp:${appVersion} ."
                }
            }
        }
    }
}


2. Pass the Parameter to the Docker Build Command:

In the pipeline above, the docker build command includes the --build-arg option to pass the APP_VERSION parameter to the Docker build context.

3. Use the Build Argument in the Dockerfile:

In your Dockerfile, you can define the build argument using the ARG instruction and use it as needed. Here’s an example:
# Use a build argument
ARG APP_VERSION

# Base image
FROM alpine:latest

# Label
LABEL version="${APP_VERSION}"

# Environment variable
ENV APP_VERSION=${APP_VERSION}

# Example command
RUN echo "Building version ${APP_VERSION}"

# Further instructions...


Explanation:

Parameter Definition in Jenkinsfile:
The parameters block in the Jenkinsfile defines a parameter MY_PARAM that can be set when triggering the pipeline.
Inside the script block, the parameter value is accessed using params.MY_PARAM.

Passing Parameter to Docker Build:
The docker.build command builds the Docker image and uses the --build-arg option to pass the parameter value to the Docker build process.

Using ARG in Dockerfile:
The ARG instruction in the Dockerfile defines a build-time variable MY_PARAM.
This variable can be used in subsequent instructions within the Dockerfile, such as RUN, ENV, etc.