From 871a4ef5cf3d7e4155f3f98db857d89caf15ea4c Mon Sep 17 00:00:00 2001 From: Aaron Gershman Date: Tue, 28 Nov 2017 11:42:04 -0600 Subject: [PATCH 1/2] Including files support --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++- assets/common.sh | 2 ++ assets/in | 16 ++++++++++++++-- assets/out | 17 +++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f81aae7..cc5c8bd 100644 --- a/README.md +++ b/README.md @@ -40,13 +40,27 @@ Deploys and retrieve artifacts from a Maven Repository Manager. ### `check`: Check for new versions of the artifact. Checks for new versions of the artifact by retrieving the `maven-metadata.xml` from -the repository. +the repository. Check will only look for new versions of the artifact, not any auxillary artifacts such as javadoc. ### `in`: Fetch an artifact from a repository. Download the artifact from the repository. +#### Parameters + +* `artifactItems`: *Optional.* Map of auxillary artifacts to download alongside the primary artifact. Takes the form _classifier: type_. It's expected auxillary artifacts will follow normal naming conventions. E.g. if the primary artifact is `my-webapp-0.0.1-beta.rc-2.jar`, then the parameter `javadoc: jar` will search for `my-webapp-0.0.1-beta.rc-2-javadoc.jar`. + +``` yaml +- get: artifact + params: + artifactItems: + javadoc: jar + sources: jar + diagram: pdf + classifier: packagingType +``` + ### `out`: Deploy artifact to a repository. @@ -60,6 +74,16 @@ Deploy the artifact to the Maven Repository Manager. * `version_file`: *Required.* The path to the version file +* `files`: *Optional.* Map of paths to auxillary artifacts to upload alongside the primary artifact. Takes the form _classifier: artifact/path-to-artifact_. The packing type will be deduced from the file extension. **Warning**: you will need to be careful with your glob pattern when specifying auxillary artifacts. You'll need to discern between the different file paths. For example, if your primary artifact is `my-artifact-0.2.3.beta-rc.7.jar`, your glob pattern will need to be... + +```yaml +- put: artifact + params: + file: artifact/my-artifact-*[0-9].*[0-9].*[0-9]-beta.*[0-9].jar + files: + javadoc: artifact/my-artifact-*-javadoc.jar +``` + ## Examples Resource configuration for an authenticated repository using a custom cert: @@ -119,3 +143,26 @@ jobs: manifest: source-code/manifest.yml path: artifact/example-webapp-*.jar ``` + +Retrieve an artifact along with auxillary artifacts, then deploy with a GitHub release: + +``` yaml +jobs: +- name: my-job + plan: + - get: source-code + - get: artifact + trigger: true + params: + artifactItems: + javadoc: jar + stubs: jar + diagram: pdf + - task: generate-github-release + file: pipeline-tasks/generate-github-release/task.yml + - put: gh-release + params: + name: task-output/release-name + tag: task-output/release-tag + globs: [artifact/example-webapp-*] +``` diff --git a/assets/common.sh b/assets/common.sh index a7680b0..d14ffdb 100755 --- a/assets/common.sh +++ b/assets/common.sh @@ -1,3 +1,5 @@ +function join { local IFS="$1"; shift; echo "$*"; } + get_group_id() { echo $1 | cut -d ":" -f 1 } diff --git a/assets/in b/assets/in index 1327a49..e9609dc 100755 --- a/assets/in +++ b/assets/in @@ -34,6 +34,7 @@ fi release_url=$(jq -r '.source.url //empty' < $payload) snapshot_url=$(jq -r '.source.snapshot_url //empty' < $payload) artifact=$(jq -r '.source.artifact //empty' < $payload) +artifactItems=$(jq -r '.params.artifactItems //empty' < $payload) version=$(jq -r '.version.version //empty' < $payload) username=$(jq -r '.source.username //empty' < $payload) password=$(jq -r '.source.password //empty' < $payload) @@ -92,14 +93,25 @@ url=$release_url [ -n "$snapshot_url" ] && [ "$isSnapshot" = true ] && url=$snapshot_url args= -args="$args -Dartifact=$artifactItem" args="$args -DoutputDirectory=$destination" args="$args -Drepository.url=$url" [ -n "$username" ] && args="$args -Drepository.username=$username"; [ -n "$password" ] && args="$args -Drepository.password=$password"; -$resource_dir/mvnw dependency:copy $args +$resource_dir/mvnw dependency:copy "$args -Dartifact=$artifactItem" + +# Deconstruct map of 'classifier: type' objects, and download +# corresponding maven repo objects using 'groupId:artifactId' and 'args' +# from the "primary" artifact +if [ -n "$artifactItems" ]; then + for classifier in $( jq -r 'keys[]' <<< $artifactItems ); do + packaging=$(jq -r ".[\"$classifier\"]" <<< $artifactItems) + artifactExtra="$groupId:$artifactId:$version:$packaging:$classifier" + $resource_dir/mvnw dependency:copy "$args -Dartifact=$artifactExtra" + done +fi + jq -n \ --arg version "$version" \ diff --git a/assets/out b/assets/out index 4d495c1..834d7d2 100755 --- a/assets/out +++ b/assets/out @@ -81,6 +81,19 @@ fi file=$(ls $file) pom_file=$(ls $pom_file) +files='' +classifiers='' +types='' +artifactItems=$( jq -r '.params.files //empty' < $payload ) +if [ -n "$artifactItems" ]; then + for classifier_key in $(jq -r 'keys[]' <<< $artifactItems); do + classifiers=$(join , $classifiers $classifier_key) + curr_file=$(jq -r ".[\"$classifier_key\"]" <<< $artifactItems ) + files=$(join , $files $curr_file) + types=$(join , $types ${curr_file##*.}) + done +fi; + if [ -f "$version_file" ]; then version=$(cat $version_file) elif [ -f "$pom_file" ]; then @@ -159,6 +172,10 @@ args="$args -Dpackaging=$packaging" [ -n "$username" ] && args="$args -Drepository.username=$username"; [ -n "$password" ] && args="$args -Drepository.password=$password"; +[ -n "$files" ] && args="$args -Dfiles=$files"; +[ -n "$classifiers" ] && args="$args -Dclassifiers=$classifiers"; +[ -n "$types" ] && args="$args -Dtypes=$types"; + $resource_dir/mvnw deploy:deploy-file $args # get the real snapshot version number From c81aca243b3e646e207c5ec4a2e548523ad86791 Mon Sep 17 00:00:00 2001 From: Mike Ball Date: Mon, 18 Nov 2019 08:34:08 -0500 Subject: [PATCH 2/2] correct spelling of 'auxiliary' in README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cc5c8bd..566b0ff 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Deploys and retrieve artifacts from a Maven Repository Manager. ### `check`: Check for new versions of the artifact. Checks for new versions of the artifact by retrieving the `maven-metadata.xml` from -the repository. Check will only look for new versions of the artifact, not any auxillary artifacts such as javadoc. +the repository. Check will only look for new versions of the artifact, not any auxiliary artifacts such as javadoc. ### `in`: Fetch an artifact from a repository. @@ -49,7 +49,7 @@ Download the artifact from the repository. #### Parameters -* `artifactItems`: *Optional.* Map of auxillary artifacts to download alongside the primary artifact. Takes the form _classifier: type_. It's expected auxillary artifacts will follow normal naming conventions. E.g. if the primary artifact is `my-webapp-0.0.1-beta.rc-2.jar`, then the parameter `javadoc: jar` will search for `my-webapp-0.0.1-beta.rc-2-javadoc.jar`. +* `artifactItems`: *Optional.* Map of auxiliary artifacts to download alongside the primary artifact. Takes the form _classifier: type_. It's expected auxiliary artifacts will follow normal naming conventions. E.g. if the primary artifact is `my-webapp-0.0.1-beta.rc-2.jar`, then the parameter `javadoc: jar` will search for `my-webapp-0.0.1-beta.rc-2-javadoc.jar`. ``` yaml - get: artifact @@ -74,7 +74,7 @@ Deploy the artifact to the Maven Repository Manager. * `version_file`: *Required.* The path to the version file -* `files`: *Optional.* Map of paths to auxillary artifacts to upload alongside the primary artifact. Takes the form _classifier: artifact/path-to-artifact_. The packing type will be deduced from the file extension. **Warning**: you will need to be careful with your glob pattern when specifying auxillary artifacts. You'll need to discern between the different file paths. For example, if your primary artifact is `my-artifact-0.2.3.beta-rc.7.jar`, your glob pattern will need to be... +* `files`: *Optional.* Map of paths to auxiliary artifacts to upload alongside the primary artifact. Takes the form _classifier: artifact/path-to-artifact_. The packing type will be deduced from the file extension. **Warning**: you will need to be careful with your glob pattern when specifying auxiliary artifacts. You'll need to discern between the different file paths. For example, if your primary artifact is `my-artifact-0.2.3.beta-rc.7.jar`, your glob pattern will need to be... ```yaml - put: artifact @@ -144,7 +144,7 @@ jobs: path: artifact/example-webapp-*.jar ``` -Retrieve an artifact along with auxillary artifacts, then deploy with a GitHub release: +Retrieve an artifact along with auxiliary artifacts, then deploy with a GitHub release: ``` yaml jobs: