Search code examples
jenkinsjenkins-pipelinedevopsjenkins-groovyjenkins-job-dsl

How to use inject environment variables (Properties File Path) in Jenkins Pipeline


Want to use the below functionality(shown in image link) in Jenkins as code, but i'm failing to do, kindly help me replicate the functionality in the image to groovy script

stage ('Build Instance') {
        sh ''' 
          bash ./build.sh -Ddisable-rpm=false
           ''' 
        env "/fl/tar/ver.prop" 
          }

Jenkins GUI usage of Env Inject


Solution

  • Got a simple workaround :

       script {
                    def props = readProperties file: '/fl/tar/ver.prop' //readProperties is a step in Pipeline Utility Steps plugin
                    env.WEATHER = props.WEATHER //assuming the key name is WEATHER in properties file
                }