如何使用Visual Studio online / Azure开发工具为nativescript设置CI / CD

问题描述 投票:0回答:1

我尝试为Nativescript应用程序设置CI / CD管道,添加了安装节点和npm安装的命令,但nativescript具有所需的依赖项。如何动态地开发Azure dev ops而无需创建具有nativescript的vm及其所有依赖项的安装和设置

所以我使用了VM并在其上安装了nativescript并使用和代理连接到机器并构建解决方案,我使用jenkins完成了同样的操作,但jenkins在vm上运行,不,我想在azure dev上移动整个管道OPS

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

nativescript nativescript-angular
1个回答
1
投票

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

需要注意的几个重要事项。首先,您的存储库的名称更改为's',这与您的权利文件的命名有关......或者至少它对我有用。我用我添加到我的存储库的bash文件解决了这个问题,该文件更改了build.xcconfig中CODE_SIGN_ENTITLEMENTS变量的路径名称。我在package.json文件中添加了一个npm run entitle命令,以便在构建之前运行它。其次,您需要将所有文件和安全密码存储在Azure Devops项目中管道下的库部分中。第三,使用经典编辑器是你最好的朋友,因为大多数工作都可以选择查看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"
© www.soinside.com 2019 - 2024. All rights reserved.