Nexus url of ivy (ant) publish task - jenkins

When using the Ivy:publish (ant)task, is there some reliable way to retrieve the URL of the published artifact.
The reason we like to know this is because we build the artifact on jenkins and would like to link the 2 processes together so we know which build produced a specific artifact. since we trigger builds fairly often and in parralel just getting the url of the last published artifact is unreliable.

You can retrieve the exact URL of the snapshot by using the REST API:
https://support.sonatype.com/entries/23674267-How-can-I-retrieve-a-snapshot-if-I-don-t-know-the-exact-filename-

Related

Get Sonarqube Analysis Status on a variable (GUI Job)

I couldn't find any solutions to this particular need.
Basically I have a GUI Job and I need the status of the Sonarqube Analysis so I can later send a POST Request with it.
(I'm aware that pipeline exists and works great but because a specific reason I need it to be GUI)
On the pipeline you have the WaitForQualityGate.status(), I've tried using this but no success.
Example of what is desired
Any insights? Thanks in advance
You can use the SonarQube Rest API to get the status.
Whenever you run SonarQube analysis through Jenkins Pipeline, upon the successful analysis you will see report-task.txt created in the workspace folder.
Note: The location of report-task.txt file depends on the tool that was used to generate it. The mvn sonar:sonar task defaults to path target/sonar. In my case, I used sonarscanner to analyse a nodejs project. So the location of report-tast.txt is .scannerwork.
Now, you will get the ceTaskUrl and ceTaskId in report-task.txt. You can use that ceTaskUrl to get the analysisId.
Then, you can use the below api to get the quality gate status using analysisId.
http://<sonarqube_host>/api/qualitygates/project_status?analysisId=$ANALYSIS_ID"
Now, try to get the curl output of the above API into a variable.
If you mean to say that you want a custom variable message to pop up in your Jenkins GUI based on the SonarQube scan status, then that would require you to:
Clone the original Jenkins source code
Add a custom HTML button/div/graphic
Compile the Jenkins code
Build the new code
Execute the generated JAR
Else, you can try some plugins available on Jenkins that would give you the ability to render conditional outputs. No promises on whether they can actually help you change the original GUI.
Any alternative traditional approach wouldn't be able to fulfill your GUI requirement.

Storing Jenkins pipeline job metadata?

Is there a way where to store some metadata from Jenkins pipeline job, e.g:
We have a Jenkinsfile which builds a gradle project, creates docker image and pushes it to google cloud
Then a "Subjob" is launched which runs integration tests (IT) on that docker image. Subjob receives a couple of parameters (one of them - the generated docker image name)
Now sometimes that IT job fails, and I would like to re-run it from the main job view, so idealy:
we have a plugin which renders a custom button in blue ocean UI on the main job
By clicking that button a subjob is invoked again with the same parameters (plugin queries the jenkins api, get params of this job, and resubmits the subjob).
The problem ? How to get/set those parameters. I could not seem to find a mechanism for that, expect artifact storage. I could get away with that by creating a simple json/text file and uploading it as artifact, and then retrieving it in my plugin, but maybe there is a better way?
Stage restart is not coming to Scripted Pipelines so that does not look like ant option.
Maybe you can use the Jenkins API to get the details of the build?
https://your_jenkins_url.com/job/job_name/lastBuild/api/json?pretty=true
Instead of lastBuild you can also use the build number or one of lastStableBuild, lastSuccessfulBuild, lastFailedBuild, lastUnstableBuild, lastUnsuccessfulBuild, lastCompletedBuild
There is a parameters key there with all parameter names and values used in the build.
More details on https://your_jenkins_url.com/job/job_name/api/
Also, any reason you can't use the replay button in the IT job?

How to send additional data elements in Jenkins Notification Plugin?

I use Jenkins Pipeline Jobs and invoke build using its remote API's.
I also use Build Notification plugin to invoke my API once the build is complete for further downstream automation. As per the plugin documentation, it provides a fixed set of data elements from the build. However as part of the build, the Job has generated some data elements which I need to provide it back to my API which gets invoked by Notification plugin (As part of the JSON Payload). Can someone help me how do pass additional data elements through this plugin? or any better ways of doing it?
For example,
1. When the pipeline job is configured with notification endpoint, the jenkins config XML has the following entry
<com.tikal.hudson.plugins.notification.HudsonNotificationProperty plugin="notification#1.11">
<endpoints>
<com.tikal.hudson.plugins.notification.Endpoint>
<protocol>HTTP</protocol>
<format>JSON</format>
<url>http://localhost/api/postStatus</url>
<event>finalized</event>
<timeout>30000</timeout>
<loglines>20</loglines>
</com.tikal.hudson.plugins.notification.Endpoint>
</endpoints>
</com.tikal.hudson.plugins.notification.HudsonNotificationProperty>
A pipeline script just builds an image and the image ID has to be sent in the notification
I did not find a perfect solution in the existing Jenkins Notification Plugin. However the solution that I used it to pass the data as part of the Log Text and parse the information in the other side.

archiver/publisher for external artifact URL

I'm generating a presigned S3 URL as part of a workflow job, which is passed into a build step that essentially runs outside of the workspace (via ssh). I've been unable to identify an existing publish or archive plugin (workflow compatible or not) that will allow setting an external URL. Is there a plugin or workaround that enables setting a URL as an artifact or the addition of simple metadata to the build results?
I'm a bit surprised that there isn't a way to publish metadata directly from a workflow -- it seems like this would be insanely useful functionally. Have I missed something obvious?
JENKINS-26918 proposes support for some of the features in the Groovy Postbuild plugin. Using core Workflow, you can call
currentBuild.description = "Published"
(or whatever your installation’s markup formatter allows).

Need help getting artifact names out of Jenkins for email

I have three Jenkins projects (Maven jobs, to be exact) that have many available parameters. I've set up a way to automate running these weekly with a set of parameters using the Build Flow plugin so that I end up running a total of 12 builds. I also have a follow-up project that exists only to send an email containing some information about the builds that ran, including a link to all 12 of the artifacts.
My problem is figuring out a way to get the artifact names from all 12 jobs. I think the best way to do that is using the REST API, but I could use some help with that.
I am using the Editable Email Notification plugin, and I have access to the job name and build number. I probably just need a script to grab the artifact name from each job.
Does anyone have experience with this?
I haven't tried the exact case you want, but you should be able to use the depth and tree parameters of the REST API to narrow down the data you need. Start with the API URL for one of the builds, which will be of the form
http://jenkins/job/jobname/buildnumber/api/json

Resources