How to setup CI/CD for nativescript using Visual studio online/Azure dev ops tools - nativescript

Im try so setup a CI/CD Pipeline for a Nativescript app, added the commands to install node and npm install but nativescript has dependencies that it need. How do I go about on Azure dev ops dynamically without having to create a vm that has nativescript and all its dependencies installed and setup
So i have used a VM and install nativescript on it and used and agent to connect to the machine and build solution, i have done the same using jenkins but jenkins was running on the vm, no i want to move the whole pipeline on azure dev ops
command used in build step: tns build android

If you don't want to use a vm you'll have to install everything needed for nativescript before building it on their hosted agent each time you create a build for your app.
A couple of important things to note. First the name of your repository is changed to 's' this messes with the naming of your entitlement file... or at least it did for me. I fix this with a bash file I add to my repository that changes the name of the path in build.xcconfig for the CODE_SIGN_ENTITLEMENTS variable. I added an npm run entitle command in my package.json file to run this before building. Second you'll want to store all files and secure passwords in the library section under pipelines in you Azure Devops project. Third, Using the classic editor is your best friend for figuring out yaml as most jobs have an option to view the YAML. You can also use the classic editor as an alternative to the YAML file
The YAML and bash file below show an example of how you can build an ipa and apk file that is stored as an artifact. You can then use that trigger a release pipeline to push the the play and app store.
# YAML File
name: Release Build
trigger:
- release/* # will start build for pull request into release branch ie. realease/version_1_0_0, release/version_2_0_0
pool:
vmImage: 'macOS-10.13'
variables:
scheme: 's' # default name/scheme created on this machine for ipa
sdk: 'iphoneos'
configuration: 'Release'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.14'
displayName: 'Install Node.js'
# Download Secure File for Android
# Note: if multiple secure files are downloaded... variable name will change and break pipeline
- task: DownloadSecureFile#1
displayName: 'download android keystore file'
inputs:
secureFile: myKeystore.keystore
#Install Apple Certificate(Distrobution)
- task: InstallAppleCertificate#2
displayName: 'Install an Apple certificate Distribution (yourcertificate.p12)'
inputs:
certSecureFile: '00000000-0000-0000-0000-000000000000' # got id from viewing file in clasic editor for pipeline
certPwd: '$(myCertificatePasswordP12)' # password stored in Library
# Install Apple Provisioning Profile(Distrobution)
- task: InstallAppleProvisioningProfile#1
displayName: 'Apple Provisioning Profile(myProvisioningProfile.mobileprovision)'
inputs:
provisioningProfileLocation: 'secureFiles' # Options: secureFiles, sourceRepository
provProfileSecureFile: '00000000-0000-0000-0000-000000000000' # Required when provisioningProfileLocation == SecureFiles
# General Set Up
- script: |
npm install -g nativescript#latest
npm install
displayName: 'Install native script and node Modules'
# variable explination
# $DOWNLOADSECUREFILE_SECUREFILEPATH is keystore file downloaded earlier
# $KEYSTORE_PASSWORD refers to the environment variable in this script which references library variable
# $(MyPlayStoreAlias) refers to library variable for your apps alias
# $BUILD_SOURCESDIRECTORY location where apk is built to
# Android
- script: |
tns build android --env.production --release --key-store-path $DOWNLOADSECUREFILE_SECUREFILEPATH --key-store-password $KEYSTORE_PASSWORD --key-store-alias $(MyPlayStoreAlias) --key-store-alias-password $KEYSTORE_PASSWORD --bundle --copy-to $BUILD_SOURCESDIRECTORY #creates apk
displayName: 'Build Android Release apk'
env:
KEYSTORE_PASSWORD: $(MyPlayStoreKeystore)
# create apk artifact
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.SourcesDirectory)/app-release.apk'
artifactName: 'apkDrop'
displayName: 'Publishing apkDrop artifact'
# have to use xcode 10.1 to meet min standards for uploading ipa... default version for this machine was lower than 10.1
#changing xcode version
- script: |
xcodebuild -version
/bin/bash -c "echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_10.1.app;sudo xcode-select --switch /Applications/Xcode_10.1.app/Contents/Developer"
xcodebuild -version
displayName: 'changing xcode to 10.1'
# Optional... was running into build issues with latest version
#downgrading cocoapods version
- script: |
sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.5.3
displayName: 'Using cocoapods version 1.5.3'
#iOS
- script: |
xcodebuild -version # makeing sure the correct xcode version is being used
pip install --ignore-installed six # fixes pip 6 error
npm run entitle #custom bash script used to change entitlement file
tns run ios --provision #see what provisioning profile and certificate are installed... helpful for debugging
tns build ios --env.production --release --bundle #creates xcworkspace
displayName: 'Build ios Release xcworkspace'
#build and sign ipa
- task: Xcode#5
displayName: 'Xcode sign and build'
inputs:
sdk: '$(sdk)' # custom var
scheme: '$(scheme)' # must be provided if setting manual path to xcworkspace
configuration: '$(configuration)' # custom var
xcodeVersion: 'specifyPath'
xcodeDeveloperDir: '/Applications/Xcode_10.1.app' #using xcode 10.1
xcWorkspacePath: 'platforms/ios/s.xcworkspace'
exportPath: '$(agent.buildDirectory)/output/$(sdk)/$(configuration)' #location where ipa file will be stored
packageApp: true #create ipa
signingOption: manual
signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)' # distribution certificate
provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)' # distribution profile
#creating ipa artifact
- task: PublishBuildArtifacts#1
displayName: 'Publishing ipaDrop artifact'
inputs:
pathtoPublish: '$(agent.buildDirectory)/output/$(sdk)/$(configuration)/s.ipa'
artifactName: 'ipaDrop'
Bash file
#!/usr/bin/env bash
# filename: pipeline-entitlements.sh
echo "Editing build.xcconfig"
TARGET_KEY="CODE_SIGN_ENTITLEMENTS"
REPLACEMENT_VALUE="s\/Resources\/YOURENTITLEMENTFILENAME.entitlements"
CONFIG_FILE="./app/App_Resources/iOS/build.xcconfig"
echo "Editing $TARGET_KEY and replaceing value with $REPLACEMENT_VALUE"
sed -i.bak "s/\($TARGET_KEY *= *\).*/\1$REPLACEMENT_VALUE/" $CONFIG_FILE
echo "Finished editing build.xcconfig"

Related

Unable to run xCode task in DevOps

I editted the yaml to reflect comments below.
I am getting the following error when I try to run my Pipeline and get to running the xCode task:
The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'GoogleAppMeasurement' from project 'Pods')
My Pipeline yaml file looks like this....
variables:
scheme: "App"
sdk: "iphoneos"
configuration: "Release"
pool:
vmImage: 'macOS-10.15' #'macOS-latest'
- task: InstallAppleCertificate#2
inputs:
certSecureFile: 'Certificates.p12'
certPwd: 'mypassword'
keychain: 'temp'
deleteCert: true
- task: InstallAppleProvisioningProfile#1
inputs:
provisioningProfileLocation: 'secureFiles'
provProfileSecureFile: Distribution_Profile.mobileprovision
removeProfile: true
- script: |
sudo gem install cocoapods
displayName: 'Install Cocoa Pods'
- script: |
pod repo update
displayName: 'Update Cocoa Pods'
- script: |
ionic cordova build ios --prod --buildFlag="-UseModernBuildSystem=0"
displayName: 'Build Ionic iOS App'
- task: Xcode#5
inputs:
actions: 'build'
scheme: 'MyProject'
configuration: '$(configuration)'
sdk: '$(sdk)'
xcWorkspacePath: '$(Build.SourcesDirectory)/platforms/ios/TechPro.xcworkspace'
xcodeVersion: 'default'
packageApp: true
signingOption: manual
signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'
teamId: 'myteamid'
exportTeamId: 'myteamid'
exportMethod: 'ad-hoc'
exportOptions: 'specify'
exportOptionsPlist: '$(Build.SourcesDirectory)/platforms/ios/MyProject/MyProject-Info.plist'
I modified the podfile to add the following...
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
end
end
end
An Xcode app must be signed and provisioned to run on a device or be published to the App Store. It looks like your ios app is not successfully signed.
This arguement CODE_SIGNING_ALLOWED=No will skip the code signing. See this thread. You can also check the task log of the Xcode task to see if your app is successfully signed.
You could try to remove the arguments CODE_SIGNING_ALLOWED=No -CODE_SIGNING_REQUIRED=NO in Xcode task and check if it could work.

How to sign APK in gitlab CI and send release to slack

I want to build an android signed APK and receive release APK through the slack channel. Tried the below script but it's not working due to my app written with JDK 8.
This is the script which I used.
image: jangrewe/gitlab-ci-android
cache:
key: ${CI_PROJECT_ID}
paths:
- .gradle/
before_script:
- export GRADLE_USER_HOME=$(pwd)/.gradle
- chmod +x ./gradlew
stages:
- build
assembleDebug:
stage: build
only:
- development
- tags
script:
- ./gradlew assembleDebug
- |
curl \
-F token="${SLACK_CHANNEL_ACCESS_TOKEN}" \
-F channels="${SLACK_CHANNEL_ID}" \
-F initial_comment="Hello team! Here is the latest APK" \
-F "file=#$(find app/build/outputs/apk/debug -name 'MyApp*')" \
https://slack.com/api/files.upload
artifacts:
paths:
- app/build/outputs/apk/debug
view raw
But is showing some java classes not found. (That java files deprecated in Java 11)
First, you need to setup slack authentication keys.
Create App in Slack
Go to Authentication Section and Generate Authentication Key.
Get Channel Id which you want to receive messages.
Mention your app name in your slack thread and add the app to the channel.
Setup those keys in your GitLab ci setting variables.
SLACK_CHANNEL_ACCESS_TOKEN = Access Token Generated by Slack App
SLACK_CHANNEL_ID = Channel Id (Check URL Last section for the channel id)
8.Copy your existing Keystore file to the repository. (Please do this if your project is private.)
7.Change GitLab script's content to the below code.
Make sure to change certificate password,key password and alias.
image: openjdk:8-jdk
variables:
# ANDROID_COMPILE_SDK is the version of Android you're compiling with.
# It should match compileSdkVersion.
ANDROID_COMPILE_SDK: "29"
# ANDROID_BUILD_TOOLS is the version of the Android build tools you are using.
# It should match buildToolsVersion.
ANDROID_BUILD_TOOLS: "29.0.3"
# It's what version of the command line tools we're going to download from the official site.
# Official Site-> https://developer.android.com/studio/index.html
# There, look down below at the cli tools only, sdk tools package is of format:
# commandlinetools-os_type-ANDROID_SDK_TOOLS_latest.zip
# when the script was last modified for latest compileSdkVersion, it was which is written down below
ANDROID_SDK_TOOLS: "6514223"
# Packages installation before running script
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
# Setup path as android_home for moving/exporting the downloaded sdk into it
- export ANDROID_HOME="${PWD}/android-home"
# Create a new directory at specified location
- install -d $ANDROID_HOME
# Here we are installing androidSDK tools from official source,
# (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well)
# after that unzipping those tools and
# then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build
- wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
# move to the archive at ANDROID_HOME
- pushd $ANDROID_HOME
- unzip -d cmdline-tools cmdline-tools.zip
- popd
- export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
# Nothing fancy here, just checking sdkManager version
- sdkmanager --version
# use yes to accept all licenses
- yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses || true
- sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${ANDROID_COMPILE_SDK}"
- sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
- sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;${ANDROID_BUILD_TOOLS}"
# Not necessary, but just for surity
- chmod +x ./gradlew
# Make Project
assembleDebug:
interruptible: true
stage: build
only:
- tags
script:
- ls
- last_v=$(git describe --abbrev=0 2>/dev/null || echo '')
- tag_message=$(git tag -l -n9 $last_v)
- echo $last_v
- echo $tag_message
- ./gradlew assembleRelease
-Pandroid.injected.signing.store.file=$(pwd)/Certificate.jks
-Pandroid.injected.signing.store.password=123456
-Pandroid.injected.signing.key.alias=key0
-Pandroid.injected.signing.key.password=123456
- |
curl \
-F token="${SLACK_CHANNEL_ACCESS_TOKEN}" \
-F channels="${SLACK_CHANNEL_ID}" \
-F initial_comment="$tag_message" \
-F "file=#$(find app/build/outputs/apk/release -name 'app*')" \
https://slack.com/api/files.upload
artifacts:
paths:
- app/build/outputs/

How to build Xamarin.Mac app on Azure pipelines

Azure pipelines has tasks that support building Xamarin apps for iOS and Android. For iOS this includes the optional capability to package a .ipa file that is suitable for upload to the store.
For my project I'm building a macOS app with Xamarin.Mac and looking to be able to automate the build in Azure pipelines, but get stuck at the packaging step. Using an msbuild invocation I can have the .app built and signed in the pipeline just fine.
The next step in the VisualStudio GUI would be clicking "Build->Archive for Publishing", which produces a .xcarchive file (not entirely sure what this is? Just a zip maybe?), then you can click "Sign and Distribute" to go through a wizard that will produce the .pkg file for submission to the store.
This part is what I can't find a way to do in the pipeline. Is there a manual command line way to build the signed .pkg file in lieu of direct support for Xamarin.Mac?
EDIT: I found this article, but adding the "/p:ArchiveOnBuild=true" argument to my msbuild invocation still has not produced an xcarchive file. The docs seem to indicate that it should, so I'm at a loss there.
Old post but never the less; I have just spent most of a day struggling with the same problem.
I found this excellent blog-post helping a bunch
https://witekio.com/blog/xamarin-mac-on-azure-devops/
The idea is basically to build on MacOS and use bash instead of Powershell
I ended up with the following pipeline:
trigger:
- master
variables:
#app data
outputAppName: '<Name of outputtet app without .app>'
projectName: '<Name of your project>'
#keys and accounts
azureSubscription: <Azure subscription for publishing result>
storageAccountKey: <storage account key>
storageAccountName: <storage account name>
storageContainerName: <storage container name>
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/$(projectName)'
configuration: 'Release'
outputArtifactPath: '$(workingDirectory)/$(projectName)/bin/$(configuration)/$(outputAppName).app'
# Agent VM image name
vmImageName: 'macos-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
displayName: Check out
clean: true
#lfs: false # whether to download Git-LFS files
submodules: true # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
persistCredentials: true
path: htpaa_backend_shared_util
condition:
- task: Bash#3
displayName: 'Change Mono version'
inputs:
targetType: 'inline'
script: |
SYMLINK=6_4_0
MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
- task: NuGetToolInstaller#1
displayName: 'Use NuGet'
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(workingDirectory)/*.sln'
- task: MSBuild#1
inputs:
solution: '$(workingDirectory)/*.sln'
platform: 'Any CPU'
configuration: '$(configuration)'
restoreNugetPackages: true
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(outputArtifactPath)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip'
replaceExistingArchive: true
verbose: true
- task: AzureCLI#2
displayName: 'CLI Copy files to Azure Storage'
inputs:
azureSubscription: '$(azureSubscription)'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az storage blob upload --account-name $(storageAccountName) --container-name $(storageContainerName) --name '$(Build.BuildId)_$(projectName).zip' --file '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip' --account-name $(storageAccountName) --account-key $(storageAccountKey)

GitLab CI. Path in yml for different users

I'm trying to set up GitLab CI for .net project. Now I'm writing script in yml file. What I want to know: the path to the msbuild.exe and mstest.exe may be different for the different team members, how the same yml script may work for different users?
Or may be I'm understand how GitLab CI work in wrong way?
The path to the mstest.exe and all other referenced executable and files is based on the machine that has the GitLab runner running.
What's on your machine or anyone else's doesn't matter; Only the build server matters, so write your gitlab .yml accordingly.
Sample .net yml file
##variables:
## increase indentation carefully, one space per cascade level.
## THIS IS YAML. NEVER USE TABS.
stages:
- build
- deploy
#BUILD
# Builds all working branches
working:
stage: build
except:
- master
script:
- echo "Build Stage"
- echo "Restoring NuGet Packages..."
- '"c:\nuget\nuget.exe" restore "SOLUTION PATH"'
# - '"c:\nuget\nuget.exe" restore "ANOTHER ABSOLUTE PATH TO YOUR SOLUTION"'
- ''
- echo "Building Solutions..."
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "SOLUTION PATH"
# Builds all stable/master pushes
stable:
stage: build
only:
- master
script:
- echo "Build Stage"
- echo "Restoring NuGet Packages..."
- '"c:\nuget\nuget.exe" restore "SOLUTION PATH"'
# - '"c:\nuget\nuget.exe" restore "ANOTHER ABSOLUTE PATH TO YOUR SOLUTION"'
- ''
- echo "Building Solutions..."
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "SOLUTION PATH"
#DEPLOY
stage: deploy
only:
- dev
script:
- echo "Deploy Stage"
#SEND TO YOUR DEV SERVER
## deploy latest master to the correct servers
stage: deploy
script:
- echo "Deploy Stage"
only:
- master
#SEND TO YOUR PRODUCTION SERVER
tags:
- .NET
#put tags here you put on your runners so you can hit the right runners when you push your code.

Xcode CI - Bot script for uploading to Fabric gives error "Failed to Detect Build Environment"

Trying to setup an Xcode CI Bot to build and upload my app to Fabric for beta distribution.
The bot builds and archives the app just fine, but fails on the Fabric upload script. Any suggestions?
Log:
IPA Path: /Users/XcodeServer/Library/Caches/XCSBuilder/Integration-c7216425c354c42adb04283fc31b6348/ExportedProduct/MyApp.ipa
2016-11-17 12:40:23.967 uploadDSYM[55991:2048496] Fabric.framework/run 1.6.2 (205)
2016-11-17 12:40:23.972 uploadDSYM[55991:2048496] Launched uploader in validation mode
error: Fabric: Failed to Detect Build Environment
Script:
IPA_PATH="${XCS_PRODUCT}"
echo "IPA Path: ${IPA_PATH}"
"${XCS_PRIMARY_REPO_DIR}"/MyApp/Pods/Fabric/run <API> <KEY> -ipaPath "${IPA_PATH}" -emails me#email.com
Solved it. I was using the wrong script (pulled from the app's build phase when setting up Fabric). You have to use the crashlytics script:
"${XCS_PRIMARY_REPO_DIR}"/MyApp/Pods/Crashlytics/submit <API> <KEY> -ipaPath "${IPA_PATH}" -emails me#test.com
I'm using this script in the Post-Integration Script Triggers
"${XCS_PRIMARY_REPO_DIR}/Pods/Crashlytics/submit" <API> <KEY> -ipaPath "${XCS_PRODUCT}"
Tested in Xcode Server 10
# Make the the encoding is correct
export LANG=en_US.UTF-8
# Remove & Copy assets
rm -r ${XCS_SOURCE_DIR}/ipa
cp -R ${XCS_OUTPUT_DIR}/ExportedProduct/Apps/ ${XCS_SOURCE_DIR}/ipa/
# Release the archive
${XCS_PRIMARY_REPO_DIR}/Pods/Crashlytics/submit <API> <Key> -ipaPath ${XCS_SOURCE_DIR}/ipa/AppName.ipa -groupAliases groupName -notifications YES
In my case, Xcode Server deletes all assets after archive.
So I added a 'copy' command in the script.

Resources