go-vela / community

Community Information for Vela (Target's official Pipeline Automation Framework)
https://go-vela.github.io/docs/
Apache License 2.0
23 stars 3 forks source link

Artifactory Plugin - Update docs to show proper regex usage #979

Closed wass3rw3rk closed 5 months ago

wass3rw3rk commented 5 months ago

Description

The artifactory plugin claims to have functionality to define a regexp pattern for the sources for an upload action. Using a step such as:

name: upload_artifacts_date
image: target/vela-artifactory
ruleset:
  event: push
secrets: [artifactory_username, artifactory_password]
parameters:
  action: upload
  log_level: trace
  path: some/path/here/
  regexp: true
  sources:
    - file_\d{4}-\d{2}-\d{2}.yml
  url: https://artifactory.example.com

results in an error such as:

[Error] path does not exist: file_\d{4}-\d{2}-\d{2}.yml
[Error] path does not exist: file_\d{4}-\d{2}-\d{2}.yml
time="2024-05-29T15:07:06Z" level=fatal msg="path does not exist: file_\\d{4}-\\d{2}-\\d{2}.yml"

Note: the double error of "path does not exist" is how it shows up.

Value

The plugin should work as advertised

Useful Information

Adding a simple test case to the upload test here https://github.com/go-vela/vela-artifactory/blob/main/cmd/vela-artifactory/upload_test.go will confirm the issue.

  1. What is the output of vela --version?
  1. What operating system is being used?
  1. Any other important details?
wass3r commented 5 months ago

it seems like you need to help the artifactory library we are using along a bit more during its rootpath check here https://github.com/jfrog/jfrog-client-go/blob/d0fbc99300a1f5d743eb79aaa76ab7d678a09030/utils/utils.go#L99. if you don't encapsulate the part that contains the regexp with parenthesis, it won't work. it won't break the path segment and consider the whole value as the root path.

indeed, digging in their docs for the CLI which uses the same library we are (https://docs.jfrog-applications.jfrog.io/jfrog-applications/jfrog-cli/cli-for-jfrog-artifactory/generic-files), i found this under the --regexp flag:

If you have specified that you are using regular expressions, then the beginning of the expression must be enclosed in parenthesis. For example: a/b/c/(.*)/file.zip

so, we might just want to augment our docs to say the same.

in the given example then, providing file_(\d{4}-\d{2}-\d{2}).yml should yield the desired behavior assuming that you have a file in the location matching that pattern.