如何使用Visual Studio Online / Azure开发人员工具为本地脚本设置CI / CD

时间:2019-03-28 08:49:31

标签: nativescript nativescript-angular

我尝试为Nativescript应用程序设置CI / CD管道,添加了用于安装node和npm install的命令,但是nativescript具有所需的依赖项。我如何动态进行Azure开发操作,而不必创建具有本机脚本及其所有依赖项的vm安装和设置

因此,我使用了VM并在其上安装了nativescript,并使用了和代理程序来连接到计算机并构建解决方案,我使用jenkins进行了同样的操作,但是jenkins在vm上运行,不,我不想移动整个管道在azure dev ops上

在构建步骤中使用的

命令:tns构建android

1 个答案:

答案 0 :(得分:0)

如果您不想使用虚拟机,则每次为应用程序创建版本时,都必须先安装nativescript所需的所有内容,然后才能在其托管代理上构建它。

需要注意的几个重要事项。首先,您的存储库名称更改为“ s”,这与您的权利文件的命名混乱了……或者至少对我而言。我使用添加到存储库中的bash文件来解决此问题,该文件更改了build.xcconfig中CODE_SIGN_ENTITLEMENTS变量的路径名称。我在package.json文件中添加了npm run entitle命令以在构建之前运行它。其次,您需要将所有文件和安全密码存储在Azure Devops项目中管道下的库部分中。第三,使用经典编辑器是找出yaml的最好朋友,因为大多数作业都有查看YAML的选项。您还可以使用经典编辑器代替YAML文件

下面的YAML和bash文件显示了如何构建作为工件存储的ipa和apk文件的示例。然后,您可以使用它触发发布管道来推动Play和应用商店。

# 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文件

#!/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"