CodeSign Error while building iOS pipeline through Jenkins and Fastlane

Viewed 344

I am trying to build iOS app using Jenkins and Fastlane. Jenkins master is a Linux machine and slave is a macOS machine, both running on AWS.

Project repository is hosted on Gitlab.

When the pipeline is run through Jenkins, it gives the following error:

The following build commands failed: CompileSwift normal arm64 CodeSign /Users/ec2-user/Library/Developer/Xcode/DerivedData/AssociatedPress-fccudiwnsqoxlobymusvrmoonnxe/Build/Intermediates.noindex/ArchiveIntermediates/AssociatedPress/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/AssociatedPress\ Notification\ Extension.appex

The contents of my fasyfile are:

node('macos') {
    {
        stage('Checkout') {
            checkout scm
        }

        stage('Resolve packages') {
            sh 'bash resolvePackages'
        }

        stage('Build Store') {
            sh 'fastlane store'
        }
    }
} 

Fastfile is as follows:-

default_platform :ios

platform :ios do

  desc "Build Store"
  lane :store do
    gym(workspace: "AssociatedPress.xcworkspace",
        scheme: "AssociatedPress",
        clean: true,
        output_directory: "./fastlane/Store",
        archive_path: "./fastlane/Store/AssociatedPressStore.xcarchive",
        buildlog_path: "./fastlane/Store/build_log",
        export_method: "app-store",
        export_options: {
            provisioningProfiles: { 
              "com.apnews.ipad.mobilenewsdevel" => "AP News Store",
              "com.apnews.ipad.mobilenewsdevel.watchkitapp" => "AP News WatchApp Store",
              "com.apnews.ipad.mobilenewsdevel.watchkitapp.watchkitextension" => "AP News WatchExtension Store",
              "com.apnews.ipad.mobilenewsdevel.notificationextension" => "AP News Notification Store",
            },
            uploadBitcode: false,
            compileBitcode: false
        })
  end   
end

Build only fails on CodeSign when it is run through Jenkins. When fastlane commands are run locally on macOS slave node, build succeeds.

Versions:-

  • macOS: 11.5.1
  • xocde version: 12.5.1
  • fastlane: 2.192.0

I have already tried some of the solutions such as unlocking the keychain before gym, running set-key-partition-list command, none of them solved the issue.

1 Answers

Anyone stumbling upon the same error, we found out that iOS does not allow you to access the keychain through SSH. Since Jenkins Master node uses SSH to access Jenkins Slave node, access to keychain is denied resulting in CodeSign error.

After spending almost a week trying to fix this, we shifted to Gitlab CI/CD instead of Jenkins and achieved our goal.

Related