Why can't Jenkins build script change to a directory? - jenkins

I am trying to build a jenkins job with below lines of code and it is failing.
cd ../../../../../
cd /home/skasturi/sdk/
cp -pr 8.0_Sprint2 8.0_Sprint3
Console output of jenkins build:
Building in workspace /var/lib/jenkins/workspace/SMGR_SDK
[SMGR_SDK] $ /bin/sh -xe /tmp/jenkins3461562069624051922.sh
+ cd ../../../../../
+ cd /home/skasturi/sdk/
/tmp/jenkins3461562069624051922.sh: line 3: cd: /home/skasturi/sdk/: Not a directory
Build step 'Execute shell' marked build as failure
Finished: FAILURE
What might be the cause of the observer behavior?

Related

Job is failing on jenkins when activating python virtual environment

I am trying to activate python Virtual environment.Jenkins war file is deployed in tomcat server.please advice what is causing this error
Running as SYSTEM
Building in workspace /opt/bitnami/apps/jenkins/jenkins_home/workspace/COMP_Admin_V2-FreeStyle
[COMP_Admin_V2-FreeStyle] $ /bin/sh -xe /opt/bitnami/apache-tomcat/temp/jenkins8889266070033436161.sh
python3.6 --version
Python 3.6.8
python3.6 -m venv ./env
source /opt/bitnami/apps/jenkins/jenkins_home/workspace/COMP_Admin_V2-FreeStyle/env/bin/activate
/opt/bitnami/apache-tomcat/temp/jenkins8889266070033436161.sh: 3: /opt/bitnami/apache-tomcat/temp/jenkins8889266070033436161.sh: source: not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE

marked build as failure in jenkins

sshpass -p Naveen#1604 scp -r /var/lib/jenkins/workspace/fastpostclose stellar#192.168.25.154:/var/www/html/fastpostclose
Build step 'Execute shell' marked build as failure
Finished: FAILURE
im using this command for moving files from jenkins to ubuntu server but it is showing build failure

How to gather all Gradle dependencies in Jenkins workspace

There is a gradle project in git and there is a Jenkins job. What should be done:
The job checkouts project code from git.
The job starts gradle build: sh "cd ${workspace}/${projectName}; ${workspace}/${projectName}/gradlew
After that I want all project dependecies to be available right there in Jenkins workspace ${workspace}/${projectName} in separate directory. Let's say ${workspace}/${projectName}/dependecies
Of course there is no way to edit the project gradle.build files.
Could it be resolved by the gradlew command flags? Or should I add some init script: ${workspace}/${projectName}/gradlew --init-script /opt/myScript. If so what it should contain?
The point is to set Jenkins workspace as gradle.home. It solves by using of --gradle-user-home flag.
The final solution:
sh "rm -rf ${workspace}/${projectName}/caches"
sh "cd ${workspace}/${projectName}"
sh "chmod +x ${workspace}/${projectName}/gradlew"
sh "${workspace}/${projectName}/gradlew build --gradle-user-home ${workspace}/${projectName}"
sh "zip -r -j ${workspace}/dependencies.zip ${workspace}/${projectName}/caches/modules-2/files-2.1"
All dependencies are stored in caches/modules-2/files-2.1 directory now. For my needs I zip it to separate dependencies.zip file.

Jenkins cannot find sh script in git repo

In my git repo I have build script located in /Src/build.sh. I have set up simple Jenkins file which runs this script:
node {
stage 'Checkout'
checkout scm
stage 'Build'
sh "chmod +x ./Src/build.sh"
sh "./Src/build.sh"
}
Execution of chmod seems to be successfull, but running build.sh gives me this error:
+ ./Src/build.sh
/var/lib/jenkins/workspace/wrksp#tmp/durable-d3f345e7/script.sh: 1:
/var/lib/jenkins/workspace/wrksp#tmp/durable-d3f345e7/script.sh: ./Src/build.sh: not found
I have no idea what is wrong?

Jenkins - groovy script returned exit code 126

I got a very simple Groovy script in Jenkins running in pipeline
For this code:
sh 'chmod +x gradlew'
sh './gradlew build --info'
I'm getting this error:
[Pipeline] sh
+ ./gradlew build --info
/var/jenkins_home/workspace/Pipeline with Gradle#tmp/durable-646d54ad/script.sh: line 1: ./gradlew: Permission denied
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 126
Finished: FAILURE
What am I missing here?
Looks like it does not have permission to run gradlew from your error message.
line 1: ./gradlew: Permission denied
You can do the following:
SSH into the jenkins machine
Switch to jenkins user
sudo su jenkins -
Check the permissions on the file gradlew using the command
ls -l /var/lib/jenkins/workspace/Pipeline with Gradle
Run the connand ./gradlew build --info from terminal and make sure it works before you run the job again
I use declarative pipelines using groovy and it works fine. I have grails installed on the machine and jenkins user can run the command. I use:
sh './gradlew dependencies && ./gradlew assemble && find ./ -name "*.war"'
Please add a comment if you have any more questions...

Resources