【问题标题】:How to setup CI/CD for nativescript using Visual studio online/Azure dev ops tools如何使用 Visual Studio Online/Azure 开发操作工具为 nativescript 设置 CI/CD
【发布时间】:2019-03-28 08:49:31
【问题描述】:

我尝试为 Nativescript 应用程序设置 CI/CD 管道,添加了安装 node 和 npm install 的命令,但 nativescript 具有它需要的依赖项。如何在无需创建安装和设置 nativescript 及其所有依赖项的 vm 的情况下动态进行 Azure 开发操作

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

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

【问题讨论】:

    标签: nativescript nativescript-angular


    【解决方案1】:

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

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

    【讨论】:

    • 我的问题是,如果您让 azure 在那里动态创建 VM,那么 sudo 无法在管道上运行,因此无法安装某些组件,我希望整个构建管道位于 azure dev ops
    • 有趣...我在他们动态创建的虚拟机上使用 sudo(如上面的 YAML 示例所示)并且没有遇到任何问题...它会给您带来任何错误吗?哪些组件不能安装?坐在 azure dev ops 上是不是指不使用存储库中的 YAML 文件,而是使用他们的经典编辑器,您可以通过 azure dev ops 网站在线编辑,还是我的意思不符合您的意思?只是想更好地了解是什么阻碍了你。
    • 我目前正在使用经典的方式来构建管道,而不是使用 yaml。以下是错误的示例。下面的 nativescript 链接显示了成功构建所需的组件。我在我的开发机器上,并且相信在构建 VM 上不存在。验证您的环境是否根据docs.nativescript.org/setup/ns-cli-setup/… 中描述的系统要求进行配置。 2019-04-25T09:06:15.9570473Z ##[错误]Bash 以代码“127”退出。 2019-04-25T09:06:15.9582276Z ##[section]Finishing: Build debug APK
    • 所以该设置适用于 linux。不确定这是否是故意的,但为了构建 iOS 应用程序,您需要运行他们的 macOS VM,这就是我的示例正在使用的。如果您只构建 android,您可以使用 linux vm,但我从未尝试过,因为我想同时为 iOS 和 android 构建。如果您尝试切换到 macOS,我敢打赌您会有更好的运气。这是在 mac docs.nativescript.org/start/ns-setup-os-x 上设置的链接。 linux有具体原因吗?
    • 我目前只为 Android 构建,这就是我使用 Linux 的原因。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-09
    相关资源
    最近更新 更多