Haaris Khatri

File Parameters in Jenkins Pipeline

1 minutes (371 words)

πŸ”—Using File Parameters in Jenkins Pipeline

Today, I was working on a Jenkins Pipeline that required handling a SQL dump file for our development environment. During this process, I encountered an important limitation: the default file parameter in Jenkins does not work with pipeline jobs; it only functions in Freestyle Project jobs.

To access file parameters in a Jenkins Pipeline, you need to use a plugin.

πŸ”—Using the Base64FileParameter Plugin

The Base64FileParameter plugin allows you to access and handle file parameters within your pipeline seamlessly. This is essential for tasks where file uploads are required.

You can install the plugin using the following link:

Plugin Link: File Parameters Plugin

πŸ”—Example Code

Here’s a simple example demonstrating how to use the Base64FileParameter in your Jenkins Pipeline:

pipeline {
    agent any
    
    parameters {
        base64File(description: 'Upload a file', name: 'FILE')
    }

    stages {
        stage('Process File') {
            steps {
                script {
                    withFileParameter('FILE') {
                        sh 'cat ${FILE}' // Example command to read the file
                    }
                }
            }
        }
    }
}


Tags: #CICD #Jenkins #Automation