Issue
While creating a task in Azure devops pipeline, I am requred to cache the NDK to reduce the build time. Hence, I am trying to write a task for the same.
For example here is what I am using for caching the gradle and konan repos
variables:
GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
KONAN_USER_HOME: /Users/runner/.konan
steps:
- bash: env
displayName: env vars
- task: Cache@2
inputs:
key: 'gradle | "$(Agent.OS)"'
restoreKeys: gradle
path: $(GRADLE_USER_HOME)
displayName: Gradle build cache
- task: Cache@2
inputs:
key: 'konan | "$(Agent.OS)" | cache'
restoreKeys: konan
path: $(KONAN_USER_HOME)
displayName: Konan build cache
they work just fine!
But for NDK, how do I know the relative repository path for my NDK and cache it, assuming the task will be something like this
- task: Cache@2
inputs:
key: 'ndk | "$(Agent.OS)"'
restoreKeys: ndk
path: $(NDK_PATH)
displayName: NDK build cache
Any help in this is highly helpful.
Solution
So, I figured this out, forgot to post here and this is what I found. 1 - to get the relative path of android-ndk from devops setup (I dont have those permissions). 2 - Then run the caching task to cache into that path
1 - get relative env vars with this bash output. CREDITS So In steps I write:
steps:
- bash: env
displayName: env vars
prints all the env variables available example gist with some vars intentionally removed from that I picked up the path relevant to my use
2021-01-19T16:17:44.4273060Z ANDROID_HOME=/Users/runner/Library/Android/sdk
2021-01-19T16:17:44.4276800Z ANDROID_SDK_ROOT=/Users/runner/Library/Android/sdk
2021-01-19T16:17:44.4320010Z ANDROID_NDK_18R_PATH=/Users/runner/Library/Android/sdk/ndk/18.1.5063045
2021-01-19T16:17:44.4328690Z ANDROID_NDK_HOME=/Users/runner/Library/Android/sdk/ndk-bundle
now the most relevant path was to ANDROID_SDK_ROOT
as this makes sense to then append /ndk
to it.
then comes my task
2 the caching task:
- create variable for path
NDK_HOME: /Users/runner/Library/Android/sdk/ndk
and add it in the cache task which completely looks like this
variables:
GRADLE_USER_HOME: $(Pipeline.Workspace)/.gradle
KONAN_USER_HOME: /Users/runner/.konan
NDK_HOME: /Users/runner/Library/Android/sdk/ndk
pool:
vmImage: 'macos-latest'
name: $(date:yyyy).$(Month)$(rev:.r)
steps:
- bash: env
displayName: env vars
- task: Cache@2
inputs:
key: 'gradle | "$(Agent.OS)"'
restoreKeys: gradle
path: $(GRADLE_USER_HOME)
displayName: Gradle build cache
- task: Cache@2
inputs:
key: 'konan | "$(Agent.OS)" | cache'
restoreKeys: konan
path: $(KONAN_USER_HOME)
displayName: Konan build cache
- task: Cache@2
inputs:
key: 'ndk | "$(Agent.OS)"'
restoreKeys: ndk
path: $(NDK_HOME)/ndk
displayName: NDK build cache
Works like a charm 🤞
One other way to dynamically create your variable from this answer. Thank you then my task looks like
steps:
- bash: env
displayName: env vars
- bash: echo "##vso[task.setvariable variable=ANDROID_SDK_ROOT;]$ANDROID_SDK_ROOT"
- task: Cache@2
inputs:
key: 'ndk | "$(Agent.OS)"'
restoreKeys: ndk
path: $(ANDROID_SDK_ROOT)/ndk
displayName: NDK build cache
works in same manner
Answered By - sud007
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.