How do you cache sdkmanager in AzureDevops?

空扰寡人 提交于 2021-02-11 15:11:29

问题


I do the following in my pipeline

          - bash: |
              $ANDROID_SDK_ROOT/tools/bin/sdkmanager 'ndk;20.0.5594570' >/dev/null
              $ANDROID_SDK_ROOT/tools/bin/sdkmanager 'ndk;21.0.6113669' >/dev/null
            displayName: "install NDK"

Which takes about 3 minutes

I was wondering if I can cache this to speed things up. However, I am not sure where it puts the files.


回答1:


It seems you want to cache ndk. You may check Pipeline caching:

https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops

Caching is added to a pipeline using the Cache task. Pipeline caching can help reduce build time by allowing the outputs or downloaded dependencies from one run to be reused in later runs, thereby reducing or avoiding the cost to recreate or redownload the same files again. Caching is especially useful in scenarios where the same dependencies are downloaded over and over at the start of each run.




回答2:


As noted in a previous answer, the Cache@2 task is supposed to be used. And as per the comment path where the ndk is downloaded to is in ANDROID_SDK_ROOT. The thing to note is ANDROID_SDK_ROOT is not a variable that is immediately accessible. It needs to be exposed.

So to put it all together with a working example:

steps:
- bash: |
    echo "##vso[task.setvariable variable=ANDROID_SDK_ROOT;]$ANDROID_SDK_ROOT"
- task: Cache@2
  inputs:
    key: 'ndk | "$(Agent.OS)"'
    path: $(ANDROID_SDK_ROOT)/ndk

- bash: |
    $ANDROID_SDK_ROOT/tools/bin/sdkmanager 'ndk;20.0.5594570' >/dev/null
    $ANDROID_SDK_ROOT/tools/bin/sdkmanager 'ndk;21.0.6113669' >/dev/null
  displayName: "install NDK"

This technique can be used in other places so that you'd get an agent pool agnostic script where the files are places in the home directory. Applies to both macOS and ubuntu pools.

steps:
- bash: |
    echo "##vso[task.setvariable variable=HOME_DIRECTORY;]$HOME"
- task: Cache@2
  inputs:
    key: 'gradlew | "$(Agent.OS)"'
    # this won't work on macOS
    # path: /home/vsts/.gradle/wrapper
    # but this will
    path: $(HOME_DIRECTORY)/.gradle/wrapper
- task: Cache@2
  inputs:
    key: 'gradle | "$(Agent.OS)"'
    path: $(HOME_DIRECTORY)/.gradle/caches


来源:https://stackoverflow.com/questions/64665884/how-do-you-cache-sdkmanager-in-azuredevops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!