Quality Gate status with Jenkins pipeline not working - jenkins

While checking quality gate status in pipeine, getting following error.
Pipeline Code is below
stage('SonarQube') {
// Run the maven build
dir("xyz_7.6_Trunk/xyz-services"){
sh ' mvn -f pom.xml clean install -Dapp.server=jboss org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar -Dsonar.host.url=http://10.11.135.66:9000 -Dsonar.scm.disabled=True -U'
}
}
stage('Quality Gate') {
timeout(time: 1, unit: ‘HOURS’) {
def qg = waitForQualityGate()
if (qg.status != ‘OK’) {
error “Pipeline aborted due to quality gate failure: ${qg.status}”
}
}
}
Error log is below.
java.lang.NoSuchMethodError: No such DSL method 'Time' 'HOURS' found among steps [acceptGitLabMR, addBadge, addErrorBadge, addGitLabMRComment, addHtmlBadge, addInfoBadge, addShortText, addWarningBadge, ansiblePlaybook, ansibleTower, ansibleVault, archive, artifactPromotion, bat, build, catchError, checkout, createSummary, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, ec2, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, getContext, git, gitChangelog, gitlabBuilds, gitlabCommitStatus, input, isUnix, junit, library, libraryResource, load, mail, milestone, nexusArtifactUploader, nexusPolicyEvaluation, nexusPublisher, node, parallel, powershell, properties, pwd, readFile, readTrusted, removeBadges,

As I see, you use scripted pipeline, so the syntax should be fine.
timeout functionality is implemented in Pipeline: Basic Steps plugin (part of Pipeline plugin). That's why I think that you need to reinstall those plugins and the issue should be fixed. Anyway, please check again the syntax of the timeout step.

Related

Jenkins Dynamic stage creation in declarative pipeline

I need to have a dynamic stages creation. Depending on the list size, it will have X amount of stages. Each of them will have stages before for allocation and preparation. As they have to run parallel, those stages have to be executed on each test bot.
The issue I have is everything has to be in a Script block due to the dynamic stage creation, but I cannot use most of the stuff like agent, stage block and such in it.
java.lang.NoSuchMethodError: No such DSL method 'agent' found among steps [VersionNumber, archive, bat, build, catchError, checkout, compareVersions, container, containerLog, deleteDir, dir, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, findFiles, gerritCheck, gerritComment, gerritReview, getContext, git, input, isUnix, jiraAddComment...
When you are in Scripted Syntax you can't use declarative syntax like agent. Instead of using agent use node
node('label') {
stage('Build') {
//Something
}

java.lang.NoSuchMethodError: No such DSL method 'string'

I tried to run a build in pipeline with groovy, which followed the example from https://www.jenkins.io/doc/pipeline/examples/:
build job: "testjob", parameters: [string(name: 'para1', value:'test_param')], propagate: false
But it failed with error:
java.lang.NoSuchMethodError: No such DSL method 'string' found among [ansiColor, archive, bat, build, catchError, checkout, deleteDir, dir, echo, emailext, emailextrecipients, error, fileExists, input, isUnix, load, mail, milestone, node, parallel, properties, publishHTML, pwd, readFile, readTrusted, retry, sh, sleep, sshagent, stage, stash, step, timeout, timestamps, tool, unarchive, unstash, waitUntil, withEnv, wrap, writeFile, ws]
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:109)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source)
The error is on "parameters: [string(name...", my understanding the string tells it is a string type parameter. It used to work, but failed after upgraded Jenkins. Could some experts help me out?

Jenkins pipeline: No such DSL method 'withNPM' found

I Am getting "No such DSL method 'withNPM' found " error with mentioned code below.
I already have my npm-global-config and npmrc config file in Jenkins config file management.
Do i need to configure or install something more?
stage('Test'){
agent {
docker {
reuseNode true
image 'cypress/browsers'
registryUrl 'https://remote-docker.artifactory.com'
args '-v $WORKSPACE:/build'
}
}
steps {
withNPM(npmrcConfig: 'npm-global-config') {
sh 'npm ci'
sh 'npm run start-test'
}
}
}
Error
java.lang.NoSuchMethodError: No such DSL method 'withNPM' found among steps [ArtifactoryGradleBuild, MavenDescriptorStep, addInteractivePromotion, archive, artifactoryBuildTrigger, artifactoryDistributeBuild, artifactoryDownload, artifactoryEditProps, artifactoryGoPublish, artifactoryGoRun, artifactoryMavenBuild, artifactoryNpmCi, artifactoryNpmInstall, artifactoryNpmPublish, artifactoryNugetRun, artifactoryPipRun, artifactoryPromoteBuild, artifactoryUpload, bat, build, buildAppend, catchError, checkout, collectEnv, collectIssues, compareVersions, conanAddRemote, conanAddUser, container, containerLog, createDockerBuildStep, createReleaseBundle, deleteDir, deleteReleaseBundle, deployArtifacts, dir, distributeReleaseBundle, dockerFingerprintFrom, dockerFingerprintRun, dockerNode, dockerPullStep, dockerPushStep, dsCreateReleaseBundle, dsDeleteReleaseBundle, dsDistributeReleaseBundle, dsSignReleaseBundle, dsUpdateReleaseBundle, echo, emailext, emailextrecipients, envVarsForTool, error, fileExists, findBuildScans, findFiles, getArtifactoryServer, getContext, getJFrogPlatformInstance, getNextSemanticVersion, git, gitChangelog, initConanClient, input, isUnix, jfPipelines, jfrogInstance, junit, library, libraryResource, load, lock, mail, milestone, newArtifactoryServer, newBuildInfo, newGoBuild, newGradleBuild, newJFrogPlatformInstance, newMavenBuild, newNpmBuild, newNugetBuild, newPipBuild, node, nodesByLabel, office365ConnectorSend, parallel, podTemplate, powershell, prependToFile, properties, timestamperConfig, timezone, tmpSpace, toolLocation, triggeredBy, unsecured, untrusted, upstream, upstreamDevelopers, userSeed, usernameColonPassword, usernamePassword, viewsTabBar, weather, withAnt, withSonarQubeEnv, workspace, x509ClientCert, zip] or globals [Artifactory, JFrog, currentBuild, docker, env, params, pipeline, scm]
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
Resolved the issue by installing Pipeline-npm plugin in jenkins.
https://plugins.jenkins.io/pipeline-npm
I recommend using NodeJS to specify your node version
plugin site: https://plugins.jenkins.io/nodejs/
here is demo
pipeline {
agent any
tools {
nodejs "your_node_js_tag_name"
}
stages {
stage('What's node version') {
steps {
sh 'node --version'
}
}
}
}

Unspecified Jenkinsfile Null Pointer Error in Workflow Steps

I encountered the following error in a Jenkinsfile pipeline I was building:
java.lang.NullPointerException
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:80)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:67)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
The issue here, primarily, is that I'm not sure exactly what is going on. Since all it's mentioning is a null pointer error, I can't exactly be sure, and I can't find anything more specific.
Here's my Jenkinsfile:
#!groovy
node {
withEnv(["WORKSPACE=${pwd()}"]) { //Setting Workspace to the current directory
stage('Clone repository...') {
checkout scm //Let checkout automagically handle pulling in all the names we need and whatnot
}
stage('Building WAR...') {
step(withMaven(
// Maven installation declared in the Jenkins "Global Tool Configuration"
maven: 'Maven 3.6.0') {
// Run the maven build
sh 'mvn clean install' //Same as running on local
sh 'mv ${WORKSPACE}/target/QUserService.war ${WORKSPACE}/target/QUserService_War-QUserService-${BRANCH_NAME}-${BUILD_NUMBER}.war'
//For above line, 'mv' is the Linux command to rename/move files, which is needed for the UCD script
}
// withMaven will discover the generated Maven artifacts, JUnit Surefire & FailSafe & FindBugs reports...
)
}
}
}
So - first, you don't need to define WORKSPACE. It is defined for you by Jenkins. You can convince yourself of this by running sh 'set' on a linux agent.
Next, you don't need to check out the project. It will already be there (assuming you're using a pipeline project).
Next, you don't need to put the withMaven inside of a step call. In a scripted pipeline, the stuff in a stage is groovy script. Step isn't required.
node {
stage('Building WAR...') {
withMaven(
maven: 'Maven 3.5.0') {
// Run the maven build
sh 'mvn clean install' //Same as running on local
}
}
I took out the move step and comment just to make it clearer.
I didn't get a null pointer error. See if removeing the step call and removing the step call make the NPE go away. If not, I'd suggest attaching the console output to attempt to see where this happens.

Jenkins Pipelines - Global library support cannot recognise vars

I have followed instructions from here in order to add some global functions to my Jenkins Pipelines. I followed the directory structure provided and I load my code through an external git repository not the one provided by Jenkins itself. Although I can add some functions under src directory and are loaded correctly as explained, I cannot load the scripts added under vars directory. Is there any way to understand what is happening. My example groovy script is very simple:
// vars/hello.groovy
def call(name) {
echo "Hello world, ${name}"
}
and i try to invoke it as follows
hello "foo"
I get the following:
> java.lang.NoSuchMethodError: No such DSL method 'hello' found among
> [archive, bat, build, catchError, checkout, deleteDir, dir, echo,
> error, fileExists, git, input, isUnix, load, mail, node, parallel,
> properties, pwd, readFile, retry, sh, sleep, stage, stash, step, svn,
> timeout, tool, unarchive, unstash, waitUntil, withEnv, wrap,
> writeFile, ws] at
> org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:107) at
> org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:113)
> at groovy.lang.GroovyObject$invokeMethod.call(Unknown Source) at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
> at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:151)
>
>
>
Has anyone faced any similar issue and how I can debug what is going on?
My Jenkins version is: 1.625.2
EDIT#1:
After as well reading this indeed after a restart the script works, but this is not efficient to restart on each change. Is there any other solution to load the vars/*.groovy scripts without a restart?

Resources