Plugin [id: 'org.sonarqube', version: '2.6.2'] was not found - jenkins

We use Sonatype Nexus as artefact repository, configured with credentials in Jenkins and it works fine.
Now i'm trying to get get a gradle project running as jenkins multibranch pipeline job using gradlew including a sonarqube code scan.
Problem:
when using only the rootProjekt.name property in settings.gradle
i get this error:
What went wrong: Plugin [id: 'org.sonarqube', version: '2.6.2'] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'org.sonarqube:org.sonarqube.gradle.plugin:2.6.2') Searched in the
following repositories:
Gradle Central Plugin Repository
The sonarqube gradle plugin is found when using the Nexus web UI, but not by gradle inside the pipeline, seems it searches only in Gradle Central Plugin Repository.
When using a Settings.gradle like that:
pluginManagement {
repositories {
maven {
url "http://nexushost/content/groups/public/"
}
}
}
rootProject.name = 'fooBar'
it works like a charm.
How to tell gradle it should always use the sonatype nexus host without having
to configure it in settings.gradle for every Job ?

You should use a Gradle init script.
For example, in every agent, create a file USER_HOME/.gradle/init.d/use-corporate-nexus.gradle, with content:
settingsEvaluated { settings ->
settings.pluginManagement {
repositories {
maven {
url "http://nexushost/content/groups/public/"
}
}
}
}

Related

Gradle tool in Jenkins Declarative Pipeline

I defined a Jenkins Declarative pipeline to CI/CD my project. I am using gradle as my build tool. However I don't want to use the Gradle Wrapper and check it int the VCS. So I planed on using the jenkins tools functionality as below so that I can update the version number if I need to in future. But it doesn't seem to work.
pipeline {
agent any
tools {
gradle "gradle-4.0"
}
stage("Compile") {
steps {
sh 'gradle project/build.gradle classes'
}
}
I get the error "script.sh: gradle: not found".
I tried to echo PATH and that doesn't contain the path of this autoinstalled gradle tool. Please help.
Looks like there is an issue on the gradle plugin for Jenkins on plugin version 1.26. Please see the link to the bug reported below.
https://issues.jenkins-ci.org/browse/JENKINS-42381

Jenkins + Gradle + Artifacts: Deploy only work once

I'm using Gradle and Jenkins and want to deploy artifacts to Artifactory. Unfortunately this deployment works only once, when I start the build in Jenkins.
If I delete the workspace and the ~/.gradle Folder on the Jenkins server the deployment works again. Deleting only the workspace alone is not enough.
Seems like a bug for me. Do I have any unknown version conflicts. Or is it something different I don't see. Thanks for any help.
Environment:
Jenkins 2.7.3
Gradle 3.1
Artifactory 4.13.0
Jenkins Artifactory Plugin 2.7.2
Gradle Build Script: (Based on example from jfrog)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '4.4.5')
}
}
allprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
repositories {
jcenter()
}
group = 'org.jfrog.example.gradle'
version = '1.0.1-SNAPSHOT'
status = 'integration'
}
artifactory {
publish {
defaults {
publishConfigs('archives')
}
}
}
// Setting this property to true will make the artifactoryPublish task
// skip this module (in our case, the root module):
artifactoryPublish.skip = true
Jenkins Artifactory Plugin Settings:
[x] Gradle-Artifactory-Integration
[x] Capture and publish build info
[x] Publish artifacts to Artifactory
[x] Publish Maven Descriptors
[x] Use Maven compatible Patterns
Rest is deactivated (not set).
Log in Jenkins (Console Output), on second run with changed version and changed source code:
Jenkins Artifactory Plugin version: 2.7.2
[Gradle] - Launching build.
[CdExampleArtifactory] $ cmd.exe /C '""C:\Program Files (x86)\Jenkins\tools\gradle-3.1\bin\gradle.bat"' --init-script c:/temp/init-artifactory8368571638486556211gradle artifactoryPublish && exit %%ERRORLEVEL%%"
:artifactoryPublish
:api:artifactoryPublish
:services:artifactoryPublish
:shared:artifactoryPublish
:services:webservice:artifactoryPublish
BUILD SUCCESSFUL
Total time: 2.422 secs
Build step 'Invoke Gradle script' changed build result to SUCCESS
Finished: SUCCESS
It looks like the task don't start the build (jar, etc.) process.
Using the latest Gradle Artifactory Plugin version 4.4.7 solves the compatibility issue with Gradle 3.1.
Gradle build snippet:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '4.4.7')
}
}
Note the version.
I found a solution for my problem.
I have to deactivate the gradle deamon on the jenkins server (via GRADLE_OPTS).

pom.xml not deploying to artifactory in Jenkins build

I am using Jenkins Artifactory plugin to deploy to an artifactory repository in my Gradle build. Since I need transitive dependency support for my artifact I need to deploy both jar and also pom.xml to artifactory.
Here is how my build.gradle looks like:
group 'com.group.name'
version '1.0'
apply plugin: 'java'
apply plugin: 'maven'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
// All of my dependencies
}
task writeNewPom << {
pom {
project {
inceptionYear '2014'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("build/poms/pom-default.xml")
}
And here is my Jenkins Config for artifactory:
Maven3-artifactory integration is checked.
And I am running this gradle tasks in my build job:
clean build writeNewPom
I am using writeNewPom task in order to create pom.xml
Problem is that only jar file is deployed but pom.xml is not being deployed to artifactory.
I tried using "include pattern" and setting is as build/libs/*.jar , build/poms/*.xml but this way even jar is not deployed.

Jenkins Artifactory Plugin does not publish artifacts using Gradle

I have an incredibly basic Gradle build file:
plugins {
id "base"
id "com.jfrog.artifactory" version "4.3.0"
}
configurations {
batchConfig
}
artifacts{
file("dist").eachFile{ zipFile ->
batchConfig zipFile
}
}
println "BatchConfig Artifacts: " + configurations.batchConfig.allArtifacts
This is executed via Jenkins and appears to work fine:
Archives Artifacts: [DefaultPublishArtifact_Decorated
module-0.0.post0.dev6+n4c62094-py2.7:egg:egg:null]
[buildinfo] Properties file found at
'/tmp/buildInfo65481565498521.properties'
:artifactoryPublish
Deploying build descriptor to:
https://ourArtifactoryServer/artifactory/api/build
Build successfully deployed.
Browse it in Artifactory under
https://ourArtifactoryServer/artifactory/webapp/builds/testGradleBuild/34
BUILD SUCCESSFUL
However the artifact is not actually uploaded to Artifactory at all.
SSL cert configuration appears to be working fine, as I had to address that first. Any suggestions as to what I'm missing here?
Looks like you do still need to utilise the artifactory closure outlined in the Gradle Artifactory Plugin. Switching back to using "archives" instead of a custom Config and then adding this to my build sorted it:
artifactory {
publish {
defaults {
publishConfigs('archives')
}
}
}

How to publish artifacts from Jenkins to uDeploy

How to publish artifacts after a successful build from Jenkins to uDeploy (IBM)?
I heard that urbandeploypublisher.hpi is required to upload this API in Jenkins but I didn't find any where.
Latest copy of the Plugin for UrbanCode Deploy is available here: https://developer.ibm.com/urbancode/plugin/jenkins/
Yes.. There is a plugin IBM UrbanCode Plugin available which you can integrate in Jenkins.
Below is the link you can see the plugin :-
https://developer.ibm.com/urbancode/plugins/
1.1.0 is the stable version that you can use. Just by integrating the plugin in Jenkins you would be able to fetch the recent build (code builded by jenkins) from your Urbancode application.
This should work...
http://www-01.ibm.com/support/docview.wss?uid=swg21664334 is the URL for the detailed steps to integrate IBM UCD and Jenkins
(It might be useful for who is trying to integrate UCD and Jenkins)
Jenkins stage for UCD deploy
stage ('UCD Deploy') {
steps {
script {
ucdDeploy {
ucdUsername="UCD_username"
ucdPassword="UCD_password"
applicationName="application_name"
environmentName="environment_name"
processName="UCD_process_name"
artifactVersion= "UCD_component_name : application_version_to_deploy"
customProps=""
}
}
}
}

Resources