Gradle tool in Jenkins Declarative Pipeline - jenkins

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

Related

How can I reference jenkinsfile declarative tools reference in my code

I have a section at the top of my jenkinsfile for tools that manages the installation. I want to see if I can reference this values later on in my declarative code.
pipeline {
agent { label 'buildfarm' }
options { buildDiscarder(logRotator(numToKeepStr: '15')) }
tools {
maven '3.6.2'
jdk 'jdk9'
}
When I generate code for the pipeline it given me code like this ...
withMaven( maven: 'Maven 3.5.0 Linux', globalMavenSettingsConfig:
'f0b3bb88-e3b7-4ba2-a1b5-8a5ab8ce02fc', mavenLocalRepo:
'.repository'){
sh "mvn clean install -U -Dmaven.test.skip=true"
}
This code resides in a library and I want the values in the tools section of the Jenkinsfile to be able to set the values for maven version in the library declarative code. Is this possible and how?

How to set build name in Jenkins Job DSL?

According to the documentation in https://jenkinsci.github.io/job-dsl-plugin/#method/javaposse.jobdsl.dsl.helpers.wrapper.MavenWrapperContext.buildName
Following code should update build name in Build History in Jenkins jobs:
// define the build name based on the build number and an environment variable
job('example') {
wrappers {
buildName('#${BUILD_NUMBER} on ${ENV,var="BRANCH"}')
}
}
Unfortunately, it is not doing it.
Is there any way to change build name from Jenkins Job DSL script?
I know I can change it from Jenkins Pipeline Script but it is not needed for me in this particular job. All I use in the job is steps.
steps {
shell("docker cp ...")
shell("git clone ...")
...
}
I would like to emphasise I am looking for a native Jenkins Job DSL solution and not a Jenkins Pipeline Script one or any other hacky way like manipulation of environment variables.
I have managed to solve my issue today.
The script did not work because it requires build-name-setter plugin installed in Jenkins. After I have installed it works perfectly.
Unfortunately, by default jobdsl processor does not inform about missing plugins. The parameter enabling that is described here https://issues.jenkins-ci.org/browse/JENKINS-37417
Here's a minimal pipeline changing the build's display name and description. IMHO this is pretty straight forward.
pipeline {
agent any
environment {
VERSION = "1.2.3-SNAPSHOT"
}
stages {
stage("set build name") {
steps {
script {
currentBuild.displayName = "v${env.VERSION}"
currentBuild.description = "#${BUILD_NUMBER} (v${env.VERSION})"
}
}
}
}
}
It results in the following representation in Jenkins' UI:
setBuildName("your_build_name") in a groovyPostBuild step may do the trick as well.
Needs Groovy Postbuild Plugin.

No tool named SonarQube Scanner 2.8 found error

I followed these instructions to download the SonarQube Scanner plugin for Jenkins. I've configured these jenkins global settings for the SonarQube scanner correctly. The SonarQube server is setup and functioning properly.
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline
But when the build runs, it produces this error: No tool named SonarQube Scanner 2.8 found.
I am using a Jenkins declarative pipeline script for pipeline build.
I am using Jenkins ver. 2.131. I am using "SonarQube Scanner for Jenkins" Plugin version 2.8.1. I believe the Jenkins server is a common linux flavor. I am NOT using any version of Maven, and don't require it to build my projects.
I figured the plugin installed the actual scanner files for me on Jenkins. Do I need to have some version of the scanner command files installed, beyond whatever the plugin provided me? Meaning, is there something other than the plugin that I need to install on by Jenkins server? I would hope the SonarQube plugin would give me everything I would need to run on Jenkins build.
Here's the relavent part of my script:
stages {
stage("SonarQube Analysis") {
agent any
steps {
script {
def scannerHome = tool 'SonarQube Scanner 2.8';
withSonarQubeEnv("foo") {
sh "${scannerHome}/bin/sonar-scanner"
}
}
}
}
Here is a screenshot of the global configuration:
I think you didn't add Scanner in Jenkins Global Tool Configuration. You can do it by doing the following steps:
click Manage Jenkins
choose Global Tool Configuration
scroll to SonarQube Scanner
add SonarQube Scanner 2.8
May be would be actual for maven's users
stage("SonarQube analysis") {
steps {
script {
def scannerHome = tool 'SonarQube Scanner';
withSonarQubeEnv('SonarQube Server') {
sh 'mvn clean package sonar:sonar'
}
}
}
}

dsl script for maven type Jenkins jobs

I writing the DSL Script for maven type Jenkins jobs.
https://jenkinsci.github.io/job-dsl-plugin/#path/mavenJob-properties
With help of above link I written almost DSL script, but unable to find the DSL script for "Build and Build setting" step sections(For maven type jobs).
Please help me how to mention the above two steps in DSL script.
I found the solution for build step for maven type jobs
add the build step (goal) after pre-build step like
mavenJob('example-1') {
preBuildSteps {
}
goals('clean install -DskipTests')
postBuildSteps {
}
}

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