|
| 1 | +{{if .Values.global.enabledTasks.buildSbt }} |
| 2 | +apiVersion: tekton.dev/v1beta1 |
| 3 | +kind: '{{default "Task" .Values.global.taskKind}}' |
| 4 | +metadata: |
| 5 | + name: '{{default "ods" .Values.taskPrefix}}-build-sbt{{- include "taskSuffix" .}}' |
| 6 | + annotations: |
| 7 | + "helm.sh/resource-policy": keep |
| 8 | +spec: |
| 9 | + description: | |
| 10 | + sbt build - TBD |
| 11 | + params: |
| 12 | + - name: working-dir |
| 13 | + description: | |
| 14 | + Working directory. The path must be relative to the root of the repository, |
| 15 | + without leading `./` and trailing `/`. |
| 16 | + type: string |
| 17 | + default: "." |
| 18 | + - name: output-dir |
| 19 | + description: >- |
| 20 | + Path to the directory into which the resulting build artifact should be copied, relative to `working-dir`. |
| 21 | + This directory may then later be used as Docker context for example. |
| 22 | + type: string |
| 23 | + default: docker |
| 24 | + - name: cache-build |
| 25 | + description: >- |
| 26 | + If enabled tasks uses or populates cache with the output dir contents (and artifacts) so that |
| 27 | + a build can be skipped if the `working-dir` contents did not change. |
| 28 | + For single build repos enabling build caching has limited benefits. For multi build repos enabling this is recommended unless the build is dependant on files outside of the working directory. See ADR caching-build-tasks for more details and workarounds. |
| 29 | + type: string |
| 30 | + default: "false" |
| 31 | + - name: build-script |
| 32 | + description: >- |
| 33 | + Build script to execute. The |
| 34 | + link:https://github.com/opendevstack/ods-pipeline/blob/master/build/package/scripts/build-sbt.sh[default script] |
| 35 | + is located in the container image. If you specify a relative path |
| 36 | + instead, it will be resolved from the workspace. See the task definition |
| 37 | + for details how the build script is invoked. |
| 38 | + type: string |
| 39 | + default: "/usr/local/bin/build-sbt" |
| 40 | + - name: sonar-quality-gate |
| 41 | + description: Whether the SonarQube quality gate needs to pass for the task to succeed. |
| 42 | + type: string |
| 43 | + default: "false" |
| 44 | + - name: sonar-skip |
| 45 | + description: Whether to skip SonarQube analysis or not. |
| 46 | + type: string |
| 47 | + default: "false" |
| 48 | + results: |
| 49 | + - description: The cache location that the build task used. If caching is not enabled this will be an empty string. |
| 50 | + name: build-reused-from-location |
| 51 | + {{- with ((.Values.sbt).sidecars) }} |
| 52 | + sidecars: |
| 53 | + {{- toYaml . | nindent 4 }} |
| 54 | + {{- end }} |
| 55 | + steps: |
| 56 | + - name: build-sbt-binary |
| 57 | + # Image is built from build/package/Dockerfile.sbt-toolset. |
| 58 | + image: '{{.Values.registry}}/{{default .Release.Namespace .Values.namespace}}/ods-sbt-toolset:{{.Values.global.imageTag | default .Chart.AppVersion}}' |
| 59 | + env: |
| 60 | + - name: DEBUG |
| 61 | + valueFrom: |
| 62 | + configMapKeyRef: |
| 63 | + key: debug |
| 64 | + name: ods-pipeline |
| 65 | + - name: HOME |
| 66 | + value: '/tekton/home' |
| 67 | + - name: CI |
| 68 | + value: "true" |
| 69 | + - name: NEXUS_URL |
| 70 | + valueFrom: |
| 71 | + configMapKeyRef: |
| 72 | + key: url |
| 73 | + name: ods-nexus |
| 74 | + - name: NEXUS_USERNAME |
| 75 | + valueFrom: |
| 76 | + secretKeyRef: |
| 77 | + key: username |
| 78 | + name: ods-nexus-auth |
| 79 | + - name: NEXUS_PASSWORD |
| 80 | + valueFrom: |
| 81 | + secretKeyRef: |
| 82 | + key: password |
| 83 | + name: ods-nexus-auth |
| 84 | + resources: |
| 85 | + {{- (.Values.sbt).resources | default dict | toYaml | nindent 8 }} |
| 86 | + script: | |
| 87 | + supply-sonar-project-properties-default |
| 88 | + echo -n "" > $(results.build-reused-from-location.path) |
| 89 | + cache_build_key=sbt |
| 90 | + if copy-build-if-cached \ |
| 91 | + --cache-build=$(params.cache-build) \ |
| 92 | + --cache-build-key="$cache_build_key" \ |
| 93 | + --cache-location-used-path=$(results.build-reused-from-location.path) \ |
| 94 | + --working-dir=$(params.working-dir) \ |
| 95 | + --output-dir=$(params.output-dir) \ |
| 96 | + --debug=${DEBUG} ; then |
| 97 | + exit 0 |
| 98 | + fi |
| 99 | + # Default build script is build/package/scripts/build-sbt.sh. |
| 100 | + set +e |
| 101 | + $(params.build-script) \ |
| 102 | + --working-dir=$(params.working-dir) \ |
| 103 | + --output-dir=$(params.output-dir) |
| 104 | + build_exit=$? |
| 105 | + set -e |
| 106 | + copy-artifacts --debug=${DEBUG} |
| 107 | + if [ $build_exit -ne 0 ]; then |
| 108 | + exit $build_exit |
| 109 | + fi |
| 110 | + if [ "$(params.cache-build)" == "true" ]; then |
| 111 | + cache-build \ |
| 112 | + --cache-build-key="$cache_build_key" \ |
| 113 | + --cache-location-used-path=$(results.build-reused-from-location.path) \ |
| 114 | + --working-dir=$(params.working-dir) \ |
| 115 | + --output-dir=$(params.output-dir) \ |
| 116 | + --debug=${DEBUG} |
| 117 | + fi |
| 118 | + workingDir: $(workspaces.source.path) |
| 119 | + {{- include "sonar-step" . | indent 4}} |
| 120 | + workspaces: |
| 121 | + - name: source |
| 122 | +{{end}} |
0 commit comments