0
votes

I am new to Jenkin Pipeline. We have maven based selenium-java Automation framework. I am creating a Jenkin Pipeline groovy script to invoke the Automation framework.

In the framework we have config.properties file in which Application url , username and password is stored.

config.properties:

Url=https://#########/login.jsp

Username=########

Password=########

Requirement: We need to take the Application URL , Username and Password as a Jenkin parameter , and run the automation suite accordingly.

Question: From Pipeline groovy script how can I update the config.properties file at runtime? Is there any possibility of creating a java class inside the framework to update config file and invoke the java class from groovy script.

I've tried the following code

node{ 
  stage("props file"){ 
    script { 
      def props = """Url=https://#########/login.jsp Username=######## 
                     Password=########""" 
      writeFile interpolate: true ,file: 'ui-automation/fw/config/config.properties', text: props 
      def str = readFile file: 'ui-automation-fw/config/config.properties' 
      echo str
    } 
   }
 } 

Appreciate any help on how to fix the code to achieve the needed result

1
please share your work around.stacktome
Hello. Work around is take the parameters in maven command and except the variables in pom.xml.sudhir ranjan Swain

1 Answers

2
votes

Use writeFile step to write the file.

The following example writes and reads the file config.properties

pipeline {
   agent any

   stages{
     stage("props file"){
        steps{
            script {

                def props = """Url=https://#########/login.jsp
Username=########
Password=########"""
                writeFile file: "config.properties", text: props
                def str =  readFile file: "config.properties"
                echo str

            }
         }
      }
   }
}

Update: If the properties file already exists you can use the readProperties step to load the properties.