Fastlane:如何将lane_context传递到另一个lane

问题描述 投票:0回答:1

我使用 Jenkins 管道来构建应用程序。在管道中,我调用 fastlane 通道两次,在两次调用之间我调用集成测试。

这是 iOS 的脚本

default_platform(:ios)

before_all do |lane, options|
  IPA_NAME = options[:ipa_name];
  ENV["SLACK_URL"] = "slack_url";
  ENV["DELIVER_ITMSTRANSPORTER_ADDITIONAL_UPLOAD_PARAMETERS"] = "-t DAV"
end

platform :ios do
  lane :build_to_browserstack do |lane, options|
    begin
      build_app()
      push_to_browserstack()
    rescue => exception
      error_do_all_operations(exception)
    end
  end
end

platform :ios do
  lane :push_to_testflight do |lane, options|
    begin
      push_to_testflight_and_s3()
      passed_do_all_operations()
    rescue => exception
      error_do_all_operations(exception)
    end
  end
end

def build_app
  clean_build_artifacts
  cert
  sigh(
    skip_install: true,
    provisioning_name: 'name'
  )
  increment_version_number(
    version_number: "1.22.3"
  )
  increment_build_number({
    build_number: latest_testflight_build_number + 1
  })
  get_version_number(
    target: ENV["SCHEME"]
  )
  get_build_number
  gym(
    scheme: ENV["SCHEME"],
    export_options: {
      provisioningProfiles: {
        "com.com.com" => "profile"
      }
    },
    output_name: IPA_NAME
  )
end

def push_to_browserstack
  upload_to_browserstack_app_automate(
    browserstack_username: "name",
    browserstack_access_key: "key",
    file_path: ENV["PATH_TO_IPA"] + IPA_NAME,
    custom_id: IPA_NAME
  )
end

def push_to_testflight_and_s3
  upload_to_testflight(
     ipa: ENV["PATH_TO_IPA"] + IPA_NAME,
     skip_submission: true,
     skip_waiting_for_build_processing: true,
     team_name: 'team'
  )
  aws_s3(
    access_key: 'key',
    secret_access_key: 'key',
    bucket: 'bucket',
    region: 'us-east-2',

    ipa: ENV["PATH_TO_IPA"] + IPA_NAME,

    path: 'path'
  )
end

def passed_do_all_operations
  slack(
    message: "New iOS build was uploaded to TestFlight",
    success: true,
    channel: "#engineering_general",
    slack_url: ENV["SLACK_URL"],
    default_payloads: [:git_branch],
    payload: {"Build Date" => Time.new.to_s,},
    attachment_properties: {
      fields: [
        {
          title: "Version number",
          value: lane_context[SharedValues::VERSION_NUMBER],
        },
        {
          title: "Build number",
          value: lane_context[SharedValues::BUILD_NUMBER],
        }
      ]
    }
  )
end

def error_do_all_operations(exception)
  slack(
    message: "iOS build was not uploaded to TestFlight",
    success: false,
    channel: "#engineering_general",
    slack_url: ENV["SLACK_URL"],
    default_payloads: [:git_branch],
    payload: {"Build Date" => Time.new.to_s,},
    attachment_properties: {
      fields: [
      {
        title: "Version number",
        value: lane_context[SharedValues::VERSION_NUMBER],
      },
      {
        title: "Build number",
        value: lane_context[SharedValues::BUILD_NUMBER],
      },
      {
        title: "Error message",
        value: exception.to_s,
        short: false
      }
      ]
    }
  )
end

我使用fastlane的参数化调用,代码和平:

before_all do |lane, options|
  IPA_NAME = options[:ipa_name];

首先我调用车道

build_to_browserstack
。现在由于我的 browserstack 帐户而出现错误,并且
error_do_all_operations()
函数可以正确生成松弛通知,其值为
lane_context[SharedValues::VERSION_NUMBER],
lane_context[SharedValues::BUILD_NUMBER],

第二次我调用车道

push_to_testflight
,这是一个问题。函数
passed_do_all_operations()
会生成没有 Lane_context 值的松弛通知。

所以问题是如何将 Lane_context 从第一次调用传递到第二次调用?

fastlane
1个回答
0
投票

我没有看到你发起了它。

示例启动lane_context。

before_each do
 lane_context[SharedValues::VERSION_NUMBER] = "your version number"
end
© www.soinside.com 2019 - 2024. All rights reserved.