Skip to content

[JENKINS-66709] Archive artifacts in console script in jenkins #232

Description

@jenkins-infra-bot

Hi,

I am trying to archive artifacts or add artifacts to a running build of a job in jenkins from the script console. I was able to add action and change them like this: 

def param = Hudson.getInstance().getItem("job").getBuild("28").getAction(hudson.model.CauseAction)
Hudson.getInstance().getItem("job").getLastBuild().actions.add(param)

but when trying to do :

def param = Hudson.getInstance().getItem("job").getBuild("28").getArtifacts(hudson.model.CauseAction)
Hudson.getInstance().getItem("job").getLastBuild().artifacts.add(param)

It returns : Results: True but nothing changed in the http://localhost:8080/job/job/32/api/xml. I also tried:

Hudson.getInstance().getItem("job").getLastBuild().getArtifactManager().archive(ws,launcher,listener,files)

But every time it throws some sort of an exception(I didn't know how to get the parameters(ws,launcher,listener,files) correctly)

The whole purpose of this is to archive artifacts from a java program that runs this script on the jenkins instance. These examples are the first steps towards achieveing this goal.

Could you please help!

Thank you in advance


Originally reported by mmakni, imported from: Archive artifacts in console script in jenkins
  • assignee: vjuranek
  • status: Open
  • priority: Major
  • component(s): archived-artifact-url-viewer-plugin, groovy-plugin, java-client-api
  • label(s): script
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 20260604-161841
Raw content of original issue

Hi,

I am trying to archive artifacts or add artifacts to a running build of a job in jenkins from the script console. I was able to add action and change them like this: 

def param = Hudson.getInstance().getItem("job").getBuild("28").getAction(hudson.model.CauseAction) Hudson.getInstance().getItem("job").getLastBuild().actions.add(param)

but when trying to do :

def param = Hudson.getInstance().getItem("job").getBuild("28").getArtifacts(hudson.model.CauseAction) Hudson.getInstance().getItem("job").getLastBuild().artifacts.add(param)

It returns : Results: True but nothing changed in the http://localhost:8080/job/job/32/api/xml. I also tried:

Hudson.getInstance().getItem("job").getLastBuild().getArtifactManager().archive(ws,launcher,listener,files)

But every time it throws some sort of an exception(I didn't know how to get the parameters(ws,launcher,listener,files) correctly)

The whole purpose of this is to archive artifacts from a java program that runs this script on the jenkins instance. These examples are the first steps towards achieveing this goal.

Could you please help!

Thank you in advance

  • environment: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions