Jenkins on Localhost with Gradle Wrapper (Access Denied) Error - shell

Following is my Machine details
Specification
Version
OS
Windows-11
Java
11
Gradle
7.3
I had setup of shell on Jenkins as well.
And Jenkins code snippet is as follows:
#!/usr/bin/env groovy
/* groovylint-disable CompileStatic, DuplicateStringLiteral, UnnecessaryGString, VariableName */
import java.text.SimpleDateFormat
pipeline {
agent any
stages {
stage('build-and-package') {
steps {
script {
sh "git update-index --chmod=+x gradlew"
sh "chmod +x gradlew"
sh "./gradlew clean assemble --stacktrace"
//sh "gradle clean build"
sh "ls -lrt"
sh "ls -lrt ./build/libs/"
}
}
}
stage('docker-build-and-push') {
steps {
//Code Commented
}
}
stage('helm-deploy') {
steps {
script {
//Code Commented
}
}
}
}
}
I have tried to provide full access rights to Jenkins workspace
Error Screen shot

Related

Jenkins Pipeline Groovy script. Script not found in workspace

The Jenkins is installed at Ubuntu. The Jenkins workspace is at /var/lib/jenkins/workspace. The github repo is at https://github.com/garyyang6/scripts. There are three scripts in the repo, build.sh, deploy.sh and quality.sh. The pipeline groovy script is as follow. After I ran the groovy script in Jenkins, it complains build.sh: not found.
At /var/lib/jenkins/workspace/Scripted_Pipeline_GitHub, I found the scripts, build.sh deploy.sh quality.sh. The folder /var/lib/jenkins/workspace/Scripted_Pipeline_GitHub#tmp is empty.
pipeline {
agent any
stages {
stage('Git-Checkout') {
steps {
echo 'Checking out from Git Repo';
git 'https://github.com/garyyang6/scripts.git'
}
}
stage('Build') {
steps {
echo "Building the checked out project";
sh 'build.sh'
}
}
stage('Unit-Test') {
steps {
echo "Running JUnit Tests";
}
}
stage('Quality-Gate') {
steps {
echo "Verifying Quality Gates";
sh 'quality.sh'
}
}
stage('Deploy') {
steps {
echo "Deploying to Stage Environment for more tests";
sh 'deploy.sh'
}
}
}
}
Erors:
Running on Jenkins in /var/lib/jenkins/workspace/Scripted_Pipeline_GitHub
/var/lib/jenkins/workspace/Scripted_Pipeline_GitHub#tmp/durable-9a8651c4/script.sh: 1: build.sh: not found

How to refer to a local Dockerfile.build file in Jenkinsfile in Scripted Pipeline

How to convert declarative pipeline as below to scripted pipeline?
I have this syntax for declarative pipeline and I would like to use the dockerfile in my jenkinsfile which is in scripted (node () ) pipeline.
pipeline {
agent { dockerfile true }
stages {
stage('Test') {
steps {
sh 'node --version'
sh 'svn --version'
}
}
}
}
You can try like this:
node {
checkout scm
def customImage = docker.build("my-image:${env.BUILD_ID}")
customImage.inside {
sh 'node —-version'
sh 'svn --version'
}
}
The build() method builds the Dockerfile in the current directory by default. This can be overridden by providing a directory path containing a Dockerfile as the second argument of the build() method, for example:
node {
checkout scm
def customImage = docker.build("my-image:${env.BUILD_ID}", "./dockerfiles/test")
customImage.inside {
sh 'node —-version'
sh 'svn --version'
}
}

Require Jenkins Pipeline script for Maven build and Maven Test from Pom.xml?

I am new to Jenkins and I have created the Maven+TestNG project in eclipse I which I have executed the sample test case to print hello world from POM.xml,which is running fine. I have pushed the project in GIT as well Now I need to execute this from Jenkins using Pipeline script for CI/CD.
I have created below Pipleline script in Jenkins pipeline tab but I am getting error which executing the script. Can you please guide me or provide me the tutorial link where I can get Jenkins pipeline example.
The script is as follow:
node {
def mvnHome
stage('Preparation') { // for display purposes
// Get some code from a GitHub repository
git 'https://github.com/jitsolution19/RestAssured_Framework.git'
// Get the Maven tool.
// ** NOTE: This 'M3' Maven tool must be configured
// ** in the global configuration.
mvnHome = tool 'Maven'
}
stage('Build') {
// Run the maven build
if (isUnix()) {
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore clean package"
} else {
bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore clean package/)
}
}
stage('Test') {
//Perform test
echo 'Execute the script'
if (isUnix()) {
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore test"
} else {
bat(/"${mvnHome}\bin\mvn" -Dmaven.test.failure.ignore test/)
}
}
stage('Results') {
junit '**/target/surefire-reports/TEST-*.xml'
archive 'target/*.jar'
}
}

jenkins declarative pipeline not working for xl-deploy using maven command

i wanna create jenkins declarative pipeline for deploying on xl-deploy using maven command. i am not using xl-deploy plugin i am just using maven command for this.
pipeline {
agent {
label 'java8'
}
tools {
maven 'M3'
}
options {
skipDefaultCheckout()
timestamps()
disableConcurrentBuilds()
timeout(time: 1, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: "${env.BRANCH_NAME}"=='master'?'10':''))
}
environment {
ARTIFACTORY = credentials('artifactory-credentials')
CF = credentials('cf-credentials')
SONAR = credentials('Sonar_Credentials')
}
stages {
stage ('Checkout') {
steps {
checkout scm
sh "git rev-parse HEAD > .git/commit-id"
script {
commit_id = readFile('.git/commit-id').trim()
pom = readMavenPom file: 'pom.xml'
currentBuild.displayName = commit_id.take(7) + "-" + pom.version
}
}
}
stage ('Build') {
steps {
sh "mvn -U -s settings.xml -gs settings.xml clean install -DskipTests=true"
}
}
stage('Publish Artifacts') {
when {
branch 'master'
}
steps {
sh "echo 'Publish JAR to Artifactory !'"
sh "mvn -s settings.xml -gs settings.xml versions:set -DnewVersion=$commit_id"
sh "mvn -s settings.xml -gs settings.xml deploy -DskipTests=true"
}
}
stage('Deploy') {
steps {
sh "wget --user ${ARTIFACTORY_USR} --password ${ARTIFACTORY_PSW} -O ${pom.artifactId}.war -nv <repo url>/${pom.artifactId}/${commit_id}/${pom.artifactId}-${commit_id}.war --server-response --"
sh "mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=<app package>-$commit_id:war -DoutputDirectory=target -Dmdep.useBaseVersion=true"
}}
}
post {
always {
deleteDir()
}
}
}
i am getting following exception:
Failed to execute goal com.xebialabs.xldeploy:xldeploy-maven-plugin:5.0.2:generate-deployment-package.
till publish, it is working fine. but it is giving exception while executing deploy stage
I would suggest upgrading to version 6.0.1 of the plugin as that version fixes some connectivity issues.
The problem might also be related to an incorrect pom.xml file, however for that to exclude as the root cause, you should at least share your pom.xml, your XL Deploy version and the loaded plugins in XL Deploy.

jhipster mvnw command not working in jenkins only

I'm trying to do Continuous Integration for the Jhipster project using Jenkins CI. In Jenkins I created as a pipeline project and tried to build with the following Jenkinsfile,
node {
stage('checkout') {
checkout scm
}
// uncomment these 2 lines and edit the name 'node-4.6.0' according to what you choose in configuration
// def nodeHome = tool name: 'node-4.6.0', type: 'jenkins.plugins.nodejs.tools.NodeJSInstallation'
// env.PATH = "${nodeHome}/bin:${env.PATH}"
stage('check tools') {
sh "node -v"
sh "npm -v"
sh "bower -v"
sh "gulp -v"
}
stage('npm install') {
sh "npm install"
}
stage('clean') {
sh "mvnw clean"
}
stage('backend tests') {
try {
sh "mvnw test"
} catch(err) {
throw err
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/surefire-reports/TEST-*.xml'])
}
}
stage('frontend tests') {
try {
sh "gulp test"
} catch(err) {
throw err
} finally {
step([$class: 'JUnitResultArchiver', testResults: '**/target/test-results/karma/TESTS-*.xml'])
}
}
stage('packaging') {
sh "mvnw package -Pprod -DskipTests"
}
}
It works fine upto npm install, on clean stage it get failure with error mvnw: command not found. I have tried with mvn clean it works but mvnw command is not working.
Also I have tried with './mvnw clean', this tries to download something from maven and fails because of connection timeout.
Any help would be appreciated.

Resources