Search code examples
androidyamlgithub-actionscicdfastlane

how to use Java String property contains/startsWith on fastlane option variable of String Type


Below is my code where I need to check if variable starts with "QA_" or not, Thanks for the appreciation in advance.

   desc "CREATE BUILD BY TAG"
   lane :createBuildByTag do |options|
       env = options[:env]
       # if env == "QA_0.0"
       # contains not working for below line
       if options[:env].contains("QA_")
            gradle(task: "clean assemblePreStageDebug")
            upload_drive(options)
       end
   end


   #  Note- I am calling above method by below command
   - name: upload driveStageAPK to Google Drive
     run: bundle exec fastlane createBuildByTag env:"${{ github.ref_name }}"   
     #QA_9.9.1 

Solution

  • are you writing Ruby code in Fastfile or using Java to check the pattern the string matches?

    If the former, the function you are looking for is include()

    So,

    ...
    
     if env && env.include?("QA_")
        #rest of code
     ...
    

    This first checks that env is not nil in order to avoid NoMEthodError.