Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue in artifact cleanup plugin while passing the parameter "repo" instead of "repos" #384

Open
prasannanjfrog opened this issue Jun 17, 2021 · 3 comments

Comments

@prasannanjfrog
Copy link

prasannanjfrog commented Jun 17, 2021

When executing the artifactCleanup plugin through the rest call we have an option to pass the parameters, one of the parameters is "repos" which is used to specify which repository the clean up action needs to run in. This works fine, however if we specify the parameter as "repo" instead of "repos" then during execution we see that the repository value is taken as null and the cleanup plugin gets executed across all the repositories. This causes cleanup and loss of data on all the repositories.

Here is an example:

Attempt 1:

In the URL I have added the variable "repos" in the REST call as shown below:

curl -X POST -v -u admin:Password1 "http://localhost:8081/artifactory/api/plugins/execute/cleanup?params=timeUnit=minute;timeInterval=1;repos=yum-test-rhel8-gcc8;dryRun=true"

Here are the repository/files that got set up for deletion:

2021-06-16T00:18:00.300Z [jfrt ] [INFO ] [4f3698e4c3debe0c] [artifactCleanup:160 ] [http-nio-8081-exec-4] - Starting artifact cleanup for repositories [yum-test-rhel8-gcc8], until 1 minutes ago with pacing interval 0 ms, dryrun: true, disablePropertiesSupport: false

Only the files in repository yum-test-rhel8-gcc8 get cleaned up.

Attempt 2:

In the URL I have added the variable "repo" in the REST call as shown below:

curl -X POST -v -u admin:Password1 "http://localhost:8081/artifactory/api/plugins/execute/cleanup?params=timeUnit=minute;timeInterval=1;repo=yum-crabel-test-rhel8-gcc8;dryRun=true"

Here are the files that got set up for deletion:

2021-06-16T00:19:05.052Z [jfrt ] [INFO ] [c8b112780dd598d7] [artifactCleanup:160 ] [http-nio-8081-exec-2] - Starting artifact cleanup for repositories null, until 1 minutes ago with pacing interval 0 ms, dryrun: true, disablePropertiesSupport: false
2021-06-16T00:19:05.053Z [jfrt ] [INFO ] [c8b112780dd598d7] [artifactCleanup:173 ] [http-nio-8081-exec-2] - Removing all artifacts not downloaded since 2021/06/16 00:18
2021-06-16T00:19:05.058Z [jfrt ] [INFO ] [c8b112780dd598d7] [artifactCleanup:207 ] [http-nio-8081-exec-2] - Found chocolatey:test.Choco.0.0.4.nupkg, 1/9 total 19071 bytes

We see that it receives null as the parameter and the package test.Choco.0.0.4.nupkg from repository chocolatey gets deleted.

If the property is not correct then we should get an error and instead the cleanup action should not be handled for all the repositories.

@DavidRadoorHummel
Copy link

DavidRadoorHummel commented Jun 23, 2021

There is already an open PR for this issue (#366).
The reason you see the behavior that you describe is that you provide a parameter which does not exist. The script then uses the default value:
def repos = params['repos'] as String[]

You can fix it by copying the edit to your own local version, so the above line becomes:
def repos = params['repos'] ? params['repos'] as String[] : ["__none__"].
In this case, if the repos argument is missing, it will not cleanup all your repos. I'd recommend running stuff like this in a sandbox environment prior to a production environment.

I hope this helps you out.

Expect more of these particularities as you use these plugins. JFrog does little to no work on this github repository which is evident from the open PRs and lack of response to issues.

@DavidRadoorHummel
Copy link

As an example, in the version of this plugin, that we use we added:

    if (!repos){
        def errorMessage = "Input argument 'Repos' most be defined"
        log.error errorMessage
        throw new CancelException(errorMessage, 400)
    }

To be completely sure that we get it if Repos is not defined.

@aps90
Copy link

aps90 commented Apr 21, 2024

Hi @prasannanjfrog i have a question.
I have not been able to get the log to print, I am making a pipeline from Jenkins and I run the plugin through curl, I already added the logger in /etc/logback.xml, I restarted the service but I cannot get the log that you show above, do you think can you help me?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants