Skip to content

Commit

Permalink
Move SERVER_SECRET param to an optional workspace
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Dec 19, 2023
1 parent d8e49dc commit 9e0d683
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
# task-maven
# `maven` Tekton Task

The `maven` Task can be used to run a Maven goal on a simple or multi-module maven project.

## Workspaces

### `source`

The `source` is a required workspace, that contains the source of the "maven" project to build. It should contain a `pom.xml`.

## Parameters

| Parameter | Type | Default | Description |
|:-------------------|:---------|:-----------|:-----------------------------------------------------------------------------------|
| `GOALS` | `string` | `package` | The `maven` goal(s) to run |
| `MAVEN_MIRROR_URL` | `string` | "" (empty) | The maven repository mirror URL to use |
| `SUBDIRECTORY` | `string` | `.` | The subdirectory of the `source` workspace on which we want to execute maven goals |

25 changes: 17 additions & 8 deletions scripts/maven-generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,25 @@ if [ -n "${PARAMS_PROXY_HOST}" -a -n "${PARAMS_PROXY_PORT}" ]; then
sed -i "s|<!-- ### HTTP proxy from ENV ### -->|$xml|" ${MAVEN_SETTINGS_FILE}
fi

if [ -n "${SERVER_USER}" -a -n "${SERVER_PASSWORD}" ]; then
xml="<server>\
<id>serverid</id>"
xml="$xml\
if [[ "${WORKSPACES_SERVER_SECRET_BOUND}" == "true" ]]; then
if test -f ${WORKSPACES_SERVER_SECRET_PATH}/username && test -f${WORKSPACES_SERVER_SECRET_PATH}/password; then
SERVER_USER=$(cat ${WORKSPACES_SERVER_SECRET_PATH}/username)
SERVER_PASSWORD=$(cat ${WORKSPACES_SERVER_SECRET_PATH}/password)
if [ -n "${SERVER_USER}" -a -n "${SERVER_PASSWORD}" ]; then
xml="<server>\
<id>serverid</id>"
xml="$xml\
<username>${SERVER_USER}</username>\
<password>${SERVER_PASSWORD}</password>"
xml="$xml\
xml="$xml\
</server>"
sed -i "s|<!-- ### SERVER's USER INFO from ENV ### -->|$xml|" ${MAVEN_SETTINGS_FILE}
echo "SERVER Creds Updated"
sed -i "s|<!-- ### SERVER's USER INFO from ENV ### -->|$xml|" ${MAVEN_SETTINGS_FILE}
echo "SERVER Creds Updated"
fi
else
echo "no 'user' or 'password' file found at workspace server_secret"
exit 1
fi
fi

if [ -n "${PARAMS_MAVEN_MIRROR_URL}" ]; then
Expand All @@ -72,4 +81,4 @@ if [ -n "${PARAMS_MAVEN_MIRROR_URL}" ]; then
<mirrorOf>central</mirrorOf>\
</mirror>"
sed -i "s|<!-- ### mirrors from ENV ### -->|$xml|" ${MAVEN_SETTINGS_FILE}
fi
fi
11 changes: 7 additions & 4 deletions templates/task-maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ spec:
- name: source
optional: false
description: The workspace consisting of maven project.
- name: sever_secret
optional: true
description: The workspace containing server secrets (user and password file)

params:
- name: GOALS
Expand All @@ -34,16 +37,16 @@ spec:
The subdirectory within the repository for sources on
which we want to execute maven goals.
default: "."
- name: SERVER_SECRET
type: string

stepTemplate:
env:
{{- $variables := list
"params.MAVEN_MIRROR_URL"
"params.SUBDIRECTORY"
"workspaces.source.path"
"workspaces.source.volume"
"workspaces.source.bound"
"workspaces.server_secret.path"
"workspaces.server_secret.bound"
}}
{{- include "environment" ( list $variables ) | nindent 6 }}

Expand Down Expand Up @@ -98,4 +101,4 @@ spec:
- name: scripts-dir
emptyDir: {}
- name: maven-settings-dir
emptyDir: {}
emptyDir: {}
2 changes: 1 addition & 1 deletion test/e2e/e2e.bats
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ source ./test/helper/helper.sh
--param="URL=${E2E_MAVEN_PARAMS_URL}" \
--param="REVISION=${E2E_MAVEN_PARAMS_REVISION}" \
--param="VERBOSE=true" \
--param="SERVER_SECRET=${E2E_MAVEN_PARAMS_SERVER_SECRET}" \
--workspace="name=server_secret,secret=${E2E_MAVEN_PARAMS_SERVER_SECRET}" \
--workspace="name=source,claimName=task-maven,subPath=source" \
--filename=test/e2e/resources/pipeline-maven.yaml \
--showlog
Expand Down

0 comments on commit 9e0d683

Please sign in to comment.