nativescript - 如何使用 Visual Studio Online/Azure 开发操作工具为 NativeScript 设置 CI/CD

标签 nativescript nativescript-angular

我尝试为 Nativescript 应用程序设置 CI/CD 管道,添加安装节点和 npm install 的命令,但 Nativescript 有它需要的依赖项。如何动态地进行 Azure 开发操作,而无需创建已安装和设置 NativeScript 及其所有依赖项的虚拟机

所以我使用了虚拟机并在其上安装了nativescript,并使用代理连接到机器并构建解决方案,我使用jenkins做了同样的事情,但是jenkins在虚拟机上运行,​​不,我想移动整个管道在 Azure 开发运营上

构建步骤中使用的命令:tns build android

最佳答案

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

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

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

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

关于nativescript - 如何使用 Visual Studio Online/Azure 开发操作工具为 NativeScript 设置 CI/CD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55393394/

相关文章:

scrollview - 如何修复在 NativeScript Angular 中未定义的 @ViewChild ElementRef?

javascript - 如何在 nativescript 中定义默认的 TabView?

css - NativeScript/NativeScript Angular - 如何为页面设置背景图片?

sqlite - 通过 nativescript 应用程序和数据库同步脱机

css - Nativescript CSS - 错误 : require's first parameter should be string

nativescript |layouts 为 ngFor 循环创建 ui

ubuntu - Genymotion 配置不正确

typescript - 使用 Angular 2 连接 Google Maps Nativescript 插件

Android - Firebase 邀请返回错误 - 结果代码 0 - 已发送电子邮件未发送短信

ios - 无法以编程方式设置网格布局高度