Answer a question

I want to read some value(ex. user Login info) from config file in Jenkins pipeline script.

downloaded plugin "Config File Provider Plugin(ver.3.10.0)"

and i create config file. enter image description here

I want to read that user info (line 2) enter image description here

anyone have ideas ?

thank you.

Answers

Here is how you can use the Config File Provider with a Groovy script. First, you have to load it to your pipeline and then execute it. So for that, you have to restructure your Groovy script as well. Please check the below.

Jenkins Pipeline

pipeline {
    agent any
    stages {
        stage('ConfigTest') {
                
            steps {
                configFileProvider([configFile(fileId: '078d4943-231c-4156-9b88-8334cd8a9402', variable: 'GroovyScript')]) {

                    echo " =========== Reading Groovy Script"
                    script {
                        def script = load("$GroovyScript")
                        script.setProperties()
                        echo "${USER_ID}"
                    }
                }
            }
        }
    }
}

Content of the Script

import groovy.transform.Field

@Field def USER_ID;
  
def setProperties() {
    USER_ID = "abcd@gmail.com"
}

return this
Logo

CI/CD社区为您提供最前沿的新闻资讯和知识内容

更多推荐