1 Reply Latest reply on Apr 8, 2015 10:39 AM by codergeek

    Externalize values used in a CLI script to a separate file

    codergeek

      Hello,

       

      is there any way to externalize values that can then be used in a CLI script like the inclusion of a CLI script in another CLI script or the usage of environment / system variables in a CLI script. Looking at the example below, is it somehow possible to define the values for url, username and password in a separate file?

       

      set url=jdbc:mysql://localhost:3306/myDB
      set username=myUser
      set password=myPasswd
      
      
      data-source add --name=myDS \ 
        --jndi-name=java:jboss/datasources/myDS \
        --driver-class=com.mysql.jdbc.Driver \
        --driver-name=mysql-connector-java-5.1.35-bin.jar \
        --connection-url=$url \
        --user-name=$username \
        --password=$password
      

       

      System information:

      (*) WildFly 8.2

      (*) Java 8

      (*) Windows 7

        • 1. Re: Externalize values used in a CLI script to a separate file
          codergeek

          I have found a solution to this problem: jboss-cli has an option called "--properties" that is not displayed in the help message. This option can be used to pass a property file to the CLI. The properties from this file have to be assigned to CLI variables before they can be used.

          Taking the example from above:

           

          dbConfig.properties:

          dbUrl=jdbc:mysql://localhost:3306/myDB
          dbUsername=myUser
          dbPasswd=myPasswd
          

           

          createDataSource.cli:

          set url=${dbUrl}
          set username=${dbUsername}
          set password=${dbPasswd}
          
          
          data-source add --name=myDS \   
            --jndi-name=java:jboss/datasources/myDS \  
            --driver-class=com.mysql.jdbc.Driver \  
            --driver-name=mysql-connector-java-5.1.35-bin.jar \  
            --connection-url=$url \  
            --user-name=$username \  
            --password=$password
          

           

          Execute script:

          jboss-cli -c --properties=dbConfig.properties --file=createDataSource.cli