Dynamically installing certificates and provisioning profiles

#1

Hello everyone,

I want to ask if it’s possible to install certificates and provisioning profiles dynamically using the script step.

Below is my script that works perfectly locally. It installs development and production certificates located on my project folder, and then build and archive my project.


#!/bin/bash

# variables (passed by script)
MACHINE_PASSWORD=$1
PACKAGE_NAME=$2 
TEAM_ID=$3 
CERT_PASSWORD=$4

# constants 
PLIST_ORIGINAL_FILE=$PWD/scripts/iosExportOptions.plist
CERTIFICATE_URL=$PWD/certificates
CERTIFICATE_DEVELOPMENT_UUID=`security cms -D -i ${CERTIFICATE_URL}/development.mobileprovision | grep -aA1 UUID | grep -o "[-a-zA-Z0-9]\{36\}"`
CERTIFICATE_DISTRIBUTION_UUID=`security cms -D -i ${CERTIFICATE_URL}/distribution.mobileprovision | grep -aA1 UUID | grep -o "[-a-zA-Z0-9]\{36\}"`

# install certificates
security unlock-keychain -p $MACHINE_PASSWORD
security import $CERTIFICATE_URL/ios_development.cer -k $HOME/Library/Keychains/login.keychain -P $CERT_PASSWORD -T /usr/bin/codesign
security import $CERTIFICATE_URL/ios_distribution.cer -k $HOME/Library/Keychains/login.keychain -P $CERT_PASSWORD -T /usr/bin/codesign

# install provisioning profiles
cp $CERTIFICATE_URL/development.mobileprovision $HOME/Library/MobileDevice/Provisioning\ Profiles/$CERTIFICATE_DEVELOPMENT_UUID.mobileprovision
cp $CERTIFICATE_URL/distribution.mobileprovision $HOME/Library/MobileDevice/Provisioning\ Profiles/$CERTIFICATE_DISTRIBUTION_UUID.mobileprovision

CERTIFICATE_IDENTITY=`security find-identity -p codesigning -v | grep -i ${TEAM_ID} | grep -o '"[^"]\+"' | sed 's/"//g'`
# security find-identity -p codesigning -v

# access App folder to starting building
cd ios/App

# move necessary files (forced)
cp -rf $PLIST_ORIGINAL_FILE ./

# replace string in plist file
sed -i '' 's/TEAM_ID/'"$TEAM_ID"'/' ./iosExportOptions.plist
sed -i '' 's/PACKAGE_NAME/'"$PACKAGE_NAME"'/' ./iosExportOptions.plist
sed -i '' 's/CERTIFICATE_DISTRIBUTION_UUID/'"$CERTIFICATE_DISTRIBUTION_UUID"'/' ./iosExportOptions.plist
sed -i '' 's/CERTIFICATE_IDENTITY/'"$CERTIFICATE_IDENTITY"'/' ./iosExportOptions.plist

# list info from project
# xcodebuild -list -project ./App.xcodeproj

# archive
xcodebuild \
   -workspace ./App.xcworkspace \
   -scheme App \
   -sdk iphoneos \
   -configuration AppStoreDistribution archive \
   -archivePath $PWD/build/App.xcarchive \
   DEVELOPMENT_TEAM=$TEAM_ID \
   PROVISIONING_PROFILE=$CERTIFICATE_URL/development.mobileprovision

xcodebuild \
    -exportArchive -archivePath \
    $PWD/build/App.xcarchive \
    -exportOptionsPlist ./iosExportOptions.plist \
    -exportPath $PWD/build

But the certificates are not installed on Bitrise. I know I can set the certificate files inside the Bitrise project, but I want to do it dynamically with files inside my project folder. Is it possible?

Thanks in advance.

0 Likes

closed #2

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

0 Likes