Release Automation

 View Only
  • 1.  How to apply regular expression on array of Strings(String[])

    Posted Jan 22, 2018 07:44 AM

    I will get Nexus artifact information in Array of Strings with full URL path. I need to display only JAR file name so I would like do regex on Array of Strings . Need Help on this ?



  • 2.  Re: How to apply regular expression on array of Strings(String[])

    Posted Jan 22, 2018 09:21 AM

    Could you elaborate a little more how this array is displayed?

     

    But other than that, If you have a String[] object you can use javascript action to do what you want. 

     

    I don't know if your question relates on the regexp to be used. If that's the case, try this

     

    \w+.jar

    Shown here Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript 



  • 3.  Re: How to apply regular expression on array of Strings(String[])

    Posted Jan 22, 2018 11:19 AM

    the Action below gives 124 artifacts in the nexus repository. I am getting these in string[] ( String Array) parameter.

     

     

    Nexus - List Artifacts In a Repository
    Found 124 artifacts:
    http://localnexus.nexus.com/nexus/service/local/repositories/my-broker/content/com/nexus/mybroker/apple-server/243-master-c33b902-20160602-211202/apple-server-243-master-c33b902-20160602-211202.jar
    http://localnexus.nexus.com/nexus/service/local/repositories/my-broker/content/com/nexus/mybroker/apple-server/251-master-1e71194-20160604-000712/apple-server-251-master-1e71194-20160604-000712.jar
    http://localnexus.nexus.com/nexus/service/local/repositories/my-broker/content/com/nexus/mybroker/apple-server/252-master-f395a10-20160604-000859/apple-server-252-master-f395a10-20160604-000859.jar
    http://localnexus.nexus.com/nexus/service/local/repositories/my-broker/content/com/nexus/mybroker/apple-server/247-master-3b7cf89-20160603-225614/apple-server-247-master-3b7cf89-20160603-225614.jar

     

     

    In next action I need to display only below as a User Input instead of above full URL link. This is possible when regex applied on this string array. But Build Regular Expression Action only can take String as a Input not a Array of Strings.

     

    243-master-c33b902-20160602-211202
    251-master-1e71194-20160604-000712
    252-master-f395a10-20160604-000859
    247-master-3b7cf89-20160603-225614



  • 4.  Re: How to apply regular expression on array of Strings(String[])

    Broadcom Employee
    Posted Jan 22, 2018 11:42 AM

    Hello,

     

    You can loop on the array and get access to each string in the array that way. Or you could pass the array to the JavaScript action and iterate through the array that way. 

     

    Cheers,

    Gregg



  • 5.  Re: How to apply regular expression on array of Strings(String[])
    Best Answer

    Posted Jan 22, 2018 11:51 AM

    So, as I said, you use the javascript action (Javascript - CA Release Automation - Integrations - CA Technologies Documentation ).

     

    Something like this (I don't have access to RA right now, but it's something like this)

    for (var i = 0; i < arrInput1.length; i++) {
         arrOutput1[i] = arrInput1[i].replace(/(\w|-)+(?=(.jar))/g, '') ;
    }


    You can see the regexp working with your examples here

    Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript 



  • 6.  Re: How to apply regular expression on array of Strings(String[])

    Posted Jan 23, 2018 12:13 PM

    Hi Marcel,

     

    Can you help me on how to give this script code ? Directly in value of Scrtipt (Input Name) ?

     

    Regards

    Mohanraj



  • 7.  Re: How to apply regular expression on array of Strings(String[])

    Posted Jan 23, 2018 01:22 PM

    Add this action to your flow

     

     

     

    the script field is the one on my other answer

    The ArrayInput1 is your Array and

     

     

    In the ArrayOutput1 you can create another array name or use the same one I guess. Your choice.



  • 8.  Re: How to apply regular expression on array of Strings(String[])

    Broadcom Employee
    Posted Jan 24, 2018 09:24 AM

    Hi Mohanraj,

     

    I'm including some links to some knowledge base articles we have that provide additional examples of how the "Execute Javascript code" action can be used - just in case they are helpful to you. 

     

    Split Strings Into Array With Execute JavaScript regex 

    Removing empty elements from Array Using Execute JavaScript action 

    How do I Convert a String Array Parameter to String Parameter 

     

     

    Kind regards,

    Gregg