Nexus Jenkins Plugin: how to inject Server URL dynamically - jenkins

I'm using the Nexus Jenkins Plugin for the uploading artifacts to the Nexus IQ server.
It looks like this inside the pipeline code:
sh "curl http://nexus-artifact-server/***/artifact.war --output artifact.war"
nexusPolicyEvaluation failBuildOnNetworkError: false, iqApplication: 'artifact.war', iqScanPatterns: [[scanPattern: '**/*.war']], iqStage: 'build', jobCredentialsId: ''
nexusPolicyEvaluation is a built-in function of the Nexus Jenkins Plugin which is doing some POST-requests to the IQ Server I think. The actual Server URL is configured inside Jenkins's system configuration i.e. it is hardcoded.
Is there any way to resolve and inject the URL dynamically? In some cases I may need a two different Nexus IQ servers but the Plugin constraints me with the single one.
Unfortunately can't find any related info at the official page

Unfortunately there is no way to configure a several Nexus IQ instances via the Jenkins Nexus Plugin. Which is a little bit strange because some teams may decide to use one IQ instance for dev, one for testing etc.
The soultion is the official Nexus IQ CLI. Works and configures perfectly.

Related

How to trigger a Jenkins build from XRay jira?

I am trying to trigger a build in Jenkins directly from Xray. I have been successfully able to create a trigger in jira and has provided the webhook url and other information needed to run the build. But on triggering the build from any Test Plan, I am getting the following error:
Error publishing web request. Response HTTP status:503
ERROR: The requested URL could not be retrieved.
When i'm hitting the same webhook url in any browser, then the build is getting triggered in jenkins, hence it seems there's no issue with the provided webhook url.
One thing to note is that our Xray is in Jira cloud whereas the Jenkins is running behind a VPN. Can anyone help me in resolving the above issue?
If your Xray on Jira Cloud is trying to acess Jenkins, the Jenkins server needs to have a public URL. If you have it behind the firewall then it's not possible for Xray or any other tool to trigger it directly.
You can call the Jenkins URL from your browser because you are probably with your vpn connected.
The possible workaround would be to use a tool such as ngrok, as mentioned in the docs, to make a tunnel, but beware with the security implications of exposing your Jenkins url to the world.
For reference, Xray cloud provides documentation/examples showcasing how to take advantage of Jira Cloud automation capabilities to trigger jobs, for example in Jenkins.

Artifactory Jenkins Plugin

I'm using the Artifactory plugin for my Java projects and also for some RPMs that I'm building (c++).
Some of Jenkins jobs are pushing artifacts using the REST API via CURL.
Is there any way via the plugin and/or via REST, to prevent overriding of an existing artifact (sometimes our versioning mechanism is not working properly, so I need to prevent this scenario)?
You should leverage the permissions for that. In Artifactory "add" and "override" are different permissions. Just prevent the user which pushes from Jenkins from overriding, and you're done.

How to trigger a Jenkins build on a new artifact in Artifactory?

Can Artifactory be used as "SCM" or source in Jenkins to trigger the builds on an particular artifact deploy?
Don't see (or miss it) anything similar in the Artifactory Jenkis plugin description (and on Jenkins side)
This could be needed for instance if there is only access to the Artifactory repository and not to the SCM with code the binaries are coming from.
Such functionality looks to be availble for Nexus (via nexus-webhook-plugin). Hard to believe that this feature is missing for Artifactory.
It's maybe not as elegant as a hook, but I believe the URLTrigger Plugin will achieve what you're looking for. Listed in their use cases:
This plugin enables users to check if new artifacts (such as binaries) have been deployed in a repository (managed for example by a repository manager such as Sonatype Nexus, JFrog Artifactory, Apache Archiva and so on).
It allows you to check the last modification date and inspect the contents of the response for changes.
You would have to use a polling interval instead of relying on Artifactory to notify Jenkins via a hook, but in my experience polling is relatively innocuous even with lots of polls at high intervals.
Now you can use Enable Artifactory trigger in a newer version.
Go to Build Triggers and check the Enable Artifactory trigger checkbox.
More Detail on GitHub Support for Artifactory trigger

Is there a way to trigger a Jenkins build after publishing an npm package to Sonatype Nexus?

Is there a way to trigger a Jenkins build after publishing an npm package to Sonatype Nexus?
I've been clicking through Sonetype's docs for Nexus and exploring my Nexus admin console. I've also tried searching for some plugins but I'm not sure if I'm not using the right terminology or if there just isn't a lot of info about calling a URL or something after publishing a package to Nexus.
I haven't tried it but it looks like you're hunting for this?
https://github.com/vbehar/nexus-webhook-plugin
You'd have to create a middleware to consume the hook and trigger a build via the jenkins api.

Got different zip structure from artifacts from Jenkins

I have been using Cloudbees Jenkins as a service and I'm trying to setup my local Jenkins which I got different results from Cloudbees Jenkins.
If I use this curl command to get the latest successful artifact.
curl http://endpoint.cloudbees.com/job/jobname/20/artifact/project_name/build/distributions/*zip*/distributions.zip
I got a zip file with this structure.
distributions/my_artifact.zip
But if I do the same command on my local Jenkins
curl http://localhost:8080/job/jobname/20/artifact/project_name/build/distributions/*zip*/distributions.zip
I just got
my_artifact.zip
which one is correct? And why they are different? I actually want my local Jenkins to produce the same results as as cloudbees.
I'm using Jenkins 1.534.
The behavior on the CloudBees hosted Jenkins is the traditional and intended behavior. It looks like you found a bug in development builds of Jenkins, which I filed as JENKINS-19947.
http://jenkins-ci.org/changelog
Read it.
* As of 1.532 download of artifact ZIPs was broken. (issue 19752)

Resources