apiVersion: tekton.dev/v1beta1 kind: Task metadata: name: jib-gradle labels: app.kubernetes.io/version: "0.1" annotations: tekton.dev/pipelines.minVersion: "0.12.1" tekton.dev/categories: Image Build tekton.dev/tags: image-build tekton.dev/displayName: "jib gradle" tekton.dev/platforms: "linux/amd64" tekton.dev/deprecated: "true" spec: description: >- This Task builds Java/Kotlin/Groovy/Scala source into a container image using Google’s Jib tool. Jib works with Gradle and Maven projects, and this template is for Gradle projects. params: - name: DIRECTORY description: The directory containing the app, relative to the source repository root default: . - name: CACHE description: The name of the volume for caching Gradle artifacts, local Maven repository, and base image layers default: empty-dir-volume - name: INSECUREREGISTRY description: Whether to allow insecure registry default: "false" workspaces: - name: source resources: outputs: - name: image type: image steps: - name: build-and-push image: gcr.io/cloud-builders/gradle@sha256:797c9936cf33fc30d82a54437541d7ea7f7825c93e3237a89d254b9bc40b0898 script: | #!/bin/sh set -o errexit # Adds Gradle init script that applies the Jib Gradle plugin. echo "initscript { repositories { maven { url 'https://plugins.gradle.org/m2' } } dependencies { classpath 'com.google.cloud.tools:jib-gradle-plugin:+' } } rootProject { afterEvaluate { if (!project.plugins.hasPlugin('com.google.cloud.tools.jib')) { project.apply plugin: com.google.cloud.tools.jib.gradle.JibPlugin } } }" > $HOME/init-script.gradle # Runs the Gradle Jib build. gradle jib \ --stacktrace --console=plain \ --init-script=$HOME/init-script.gradle \ --gradle-user-home=$HOME/.gradle \ -Dgradle.user.home=$HOME/.gradle \ -Duser.home=$HOME \ -Djib.allowInsecureRegistries=$(params.INSECUREREGISTRY) \ -Djib.to.image=$(resources.outputs.image.url) workingDir: $(workspaces.source.path)/$(params.DIRECTORY) env: - name: HOME value: /workspace - name: "DOCKER_CONFIG" value: $(credentials.path)/.docker/ volumeMounts: # empty volume required to make the Gradle home globally writable - name: empty-dir-volume mountPath: /workspace/.gradle subPath: gradle-user-home - name: $(params.CACHE) mountPath: /workspace/.gradle/caches subPath: gradle-caches - name: $(params.CACHE) mountPath: /workspace/.gradle/wrapper subPath: gradle-wrapper - name: $(params.CACHE) mountPath: /workspace/.m2 subPath: m2-cache - name: $(params.CACHE) mountPath: /workspace/.cache subPath: jib-cache securityContext: runAsUser: 0 volumes: - name: empty-dir-volume emptyDir: {}