为什么bitbucket管道不创建缓存?

时间:2019-02-14 09:56:03

标签: bitbucket bitbucket-pipelines

这是我的脚本之后服务器上的结果树:

> pwd
/opt/atlassian/pipelines/agent/build
> tree -d
.
├── android-sdk-linux
│   ├── build-tools
│   │   └── 28.0.3
...
├── app
│   ├── build
...
└── readme
8005 directories

这是我的https://opatry.net/2017/11/06/bitbucket-pipelines-for-android/脚本:

ci_install.sh

#!/usr/bin/env bash

set -eu

cur_dir=$(cd "$(dirname "$0")"; pwd)
origin_dir=$(cd "${cur_dir}/.."; pwd)
app_dir="${origin_dir}/android"
output_dir="${origin_dir}/artifacts"

default_android_sdk_zip_version="3859397"
android_sdk_zip_version=${1:-${default_android_sdk_zip_version}}

case $(uname -s) in
  Linux)
    os="linux"
  ;;
  Darwin)
    os="darwin"
  ;;
  CYGWIN*|MINGW*)
    os="windows"
  ;;
  *)
    echo "!! Unsupported OS $(uname -s)"
    exit 1
  ;;
esac

export ANDROID_HOME="${origin_dir}/android-sdk-${os}"

if [ ! -f "${ANDROID_HOME}/tools/bin/sdkmanager" ]; then
  # Download and unzip Android sdk
  echo "Downloading Android SDK '${android_sdk_zip_version}' for '${os}'"
  wget "https://dl.google.com/android/repository/sdk-tools-${os}-${android_sdk_zip_version}.zip"
  unzip "sdk-tools-${os}-${android_sdk_zip_version}.zip" -d "${ANDROID_HOME}"
  rm "sdk-tools-${os}-${android_sdk_zip_version}.zip"
fi

# Add Android binaries to PATH
export PATH="${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools:${PATH}"

# Accept all licenses (source: http://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences)
echo "Auto Accepting licenses"
mkdir -p "$ANDROID_HOME/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "${ANDROID_HOME}/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "${ANDROID_HOME}/licenses/android-sdk-preview-license"

# Update android sdk
echo "Downloading packages described by ${cur_dir}/package_file.txt"
cat "${cur_dir}/package_file.txt"
( sleep 5 && while [ 1 ]; do sleep 1; echo y; done ) | sdkmanager --package_file="${cur_dir}/package_file.txt"

package_file.txt

platform-tools
build-tools;26.0.2
platforms;android-26

bitbucket-pipelines.yml:

image: java:8

pipelines:
  branches:
    master:
      - step:
          caches:
            - gradle
            - android-sdk
          script:
            - bash ./build/ci_install.sh
            - ANDROID_HOME=$PWD/android-sdk-linux bash ./build/android.sh

definitions:
  caches:
    android-sdk: android-sdk-linux
    gradle: gradle

结果:

Build teardown
You already have a 'gradle' cache so we won't create it again
Assembling contents of new cache 'android-sdk'

但是在管道-> 缓存-> 依赖缓存中,android-sdk的缓存未显示: enter image description here

然后在下一次运行:

Cache "android-sdk": Downloading
Cache "android-sdk": Not found

1 个答案:

答案 0 :(得分:0)

一切正常。我的ci_install.sh文件位于/MyProject/utils/pipelines/ci_install.sh中,因此android-sdk-linux是在/opt/atlassian/pipelines/agent/build/utils/android-sdk-linux文件夹中创建的

所以我将文件ci_install.sh移到了/MyProject/pipelines/ci_install.sh,现在在/opt/atlassian/pipelines/agent/build/android-sdk-linux文件夹中创建了android-sdk-linux

从我的项目中删除了文件夹utils