Fastlane: How can I "increment_build_number" of one target only?

Here is a plug-in to increment the build number.

This is what it looks like in the Fastfile:

increment_build_number_in_plist(        
   target:"MyAwesomeApp"
)

And what about specifying as a parameter the .plist file you want to bump?? something like:

plist_path: "./Info.plist"

I have created my custom lane that by using "xcodeproj" is able to set both the version and the build number for a specific target name.

# Sets the "VERSION" and "BUILD" number for a target
#
# @param args [Hash] Key value arguments. All the values are Strings. List: 
#   - target_name: The name of the target (REQUIRED)
#   - version: The version number to be used (REQUIRED)
#   - build: The build number to be used (REQUIRED)
#
desc "Sets the \"VERSION\" and \"BUILD\" number for a target"
lane :set_version_build_number do |args|
    puts("\"set_version_build_number\" lane with ARGUMENTS: #{args}")

    target_name = args[:target_name]
    version = args[:version]
    build = args[:build]

    raise(StandardError, "Invalid ARGUMENTS for: \"set_version_build_number\" LANE") unless (
        target_name != nil &&
        version != nil &&
        build != nil
    )

    puts("Variables:")
    puts("\ttarget_name: #{target_name}")
    puts("\tversion: #{version}")
    puts("\tbuild: #{build}")
    
    project_url = find_xcode_project()
    raise(StandardError, "Invalid Xcode project for: \"set_version_build_number\" LANE") unless project_url != nil
    project = Xcodeproj::Project.open(project_url)

    xc_target = project.targets.find { |target| target.name == target_name }
    raise(StandardError, "Invalid target for: \"set_version_build_number\" LANE") unless xc_target != nil

    xc_target.build_configurations.each { |build_configuration| 
        build_configuration.build_settings["MARKETING_VERSION"] = version
        build_configuration.build_settings["CURRENT_PROJECT_VERSION"] = build
    }

    project.save()
end

Where:

# Finds the location for an Xcode project within the current directory and all his parents
#
# @return [String] Full path to the Xcode project or nil if unsuccess
#
def find_xcode_project ()
    absolute_dir_path = Dir.getwd
    loop do
        entries = Dir.entries(absolute_dir_path)
        index = entries.find_index{ |entry| entry.include?(".xcodeproj") }
        if index != nil
          return "#{absolute_dir_path}/#{entries[index]}"
        end
  
        absolute_dir_path = File.dirname(absolute_dir_path)
        if absolute_dir_path == nil || absolute_dir_path == "/"
          break
        end
    end
  
    return nil
end

It can easily be used:

bundle exec fastlane set_version_build_number target_name:TargetApp version:2.0 build:3

Of course don't forget to add this into the Fastlane file:

require "xcodeproj" 

and this into the Gemfile

gem "xcodeproj"

I could easily add this option to the fastlane action, but would need the agvtool equivalent for doing that. The increment_build_number step is mostly a wrapper around agvtool.

You can find more information on Apple's Docs: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/agvtool.1.html

Tags:

Ios

Fastlane