Build step 'Execute shell' marked build as failure - jenkins

I have a build step in my jenkins project. This is an Execute Shell step.
The following is the command is what I am running.
sudo gcloud --project=xxxx preview app deploy app.yaml ==version=1
During the deployment the above step breaks the build, with the following error.
sudo gcloud --project=cfc-melbourne-website preview app deploy app.yaml ==version=1
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
sudo: no tty present and no askpass program specified
Build step 'Execute shell' marked build as failure
No JDK named ‘null’ found
ERROR: Build step failed with exception
com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials$AccountIdNotSetException
at com.google.jenkins.plugins.credentials.oauth.GoogleRobotPrivateKeyCredentials.getUsername(GoogleRobotPrivateKeyCredentials.java:152)
at com.google.jenkins.plugins.credentials.oauth.RemotableGoogleCredentials.<init>(RemotableGoogleCredentials.java:54)
at com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials.forRemote(GoogleRobotCredentials.java:204)
at com.google.jenkins.plugins.storage.AbstractUpload.initiateUploadsAtWorkspace(AbstractUpload.java:342)
at com.google.jenkins.plugins.storage.AbstractUpload.perform(AbstractUpload.java:173)
at com.google.jenkins.plugins.storage.GoogleCloudStorageUploader.perform(GoogleCloudStorageUploader.java:109)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
at hudson.model.Build$BuildExecution.post2(Build.java:185)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
at hudson.model.Run.execute(Run.java:1766)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Build step 'Google Cloud Storage Uploader' marked build as failure
Finished: FAILURE
How do I resolve this ?

The no tty present error indicates that you have the requiretty setting in your sudoers file. This will require a tty. To solve this you can add your user to that file and turn .
change your sudoers-file:
vi /etc/sudoers
and add (assuming it's your jenkins-user):
Defaults:jenkins !authenticate
Normally your jenkins user can use sudo-commands without authentication.

Related

Jenkins build over ssh times out on first attempt

I have successfully set up a build with Jenkins (version 2.375.1) that is triggered by a GitHub web-hook. Dockerized Jenkins is running on an Ubuntu VM locally.
If I push from my local machine to GitHub, then this will initiate a build using build step: "Execute shell script on remote host using ssh" on the target AWS and run some steps to install the application. However, if I leave it too long the job times out. If I make a change and push again, or if I just hit build now, then the build is successful.
It seems like the connection from Jenkins to AWS is going to sleep and it requires the first attempt to "wake it up". I can't find any reference to this behaviour anywhere.
At the end of the console output....
[SSH] executing...
[SSH] Exception:Session.connect: java.net.SocketTimeoutException: Read timed out
com.jcraft.jsch.JSchException: Session.connect: java.net.SocketTimeoutException: Read timed out
at com.jcraft.jsch.Session.connect(Session.java:565)
at org.jvnet.hudson.plugins.CredentialsSSHSite.createSession(CredentialsSSHSite.java:132)
at org.jvnet.hudson.plugins.CredentialsSSHSite.executeCommand(CredentialsSSHSite.java:208)
at org.jvnet.hudson.plugins.SSHBuilder.perform(SSHBuilder.java:104)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:818)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:164)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:526)
at hudson.model.Run.execute(Run.java:1900)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:107)
at hudson.model.Executor.run(Executor.java:449)
Build step 'Execute shell script on remote host using ssh' marked build as failure
Finished: FAILURE

ERROR: Build step failed with exception net.sf.json.JSONException: null object while bulding and publishing docker image

I have created a springboot project with docker file. I have tomcat running in my windows machine. I have jenkins running inside webapps folder of tomcat server. I have created a job in jenkins and integrated github and added build and publish plogin to build and publish the docker image. Now when i am building the job. The project build is successfull using maven and a war is created but image build and publish is failing again and again. Below error is coming. I am not able to locate the DockerRegistryEndpoint.java file.
ERROR: Build step failed with exception
net.sf.json.JSONException: null object
at net.sf.json.JSONObject.verifyIsNull(JSONObject.java:2688)
at net.sf.json.JSONObject.element(JSONObject.java:1733)
at net.sf.json.JSONObject.element(JSONObject.java:1716)
at net.sf.json.JSONObject.put(JSONObject.java:2328)
at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryToken$1.call(DockerRegistryToken.java:150)
at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryToken$1.call(DockerRegistryToken.java:125)
at hudson.remoting.LocalChannel.call(LocalChannel.java:47)
at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryToken.newKeyMaterialFactory(DockerRegistryToken.java:125)
at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint.newKeyMaterialFactory(DockerRegistryEndpoint.java:259)
at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint.newKeyMaterialFactory(DockerRegistryEndpoint.java:244)
at org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint.newKeyMaterialFactory(DockerRegistryEndpoint.java:236)
at com.cloudbees.dockerpublish.DockerBuilder$Perform.executeCmd(DockerBuilder.java:455)
at com.cloudbees.dockerpublish.DockerBuilder$Perform.executeCmd(DockerBuilder.java:431)
at com.cloudbees.dockerpublish.DockerBuilder$Perform.buildAndTag(DockerBuilder.java:373)
at com.cloudbees.dockerpublish.DockerBuilder$Perform.exec(DockerBuilder.java:311)
at com.cloudbees.dockerpublish.DockerBuilder$Perform.access$100(DockerBuilder.java:291)
at com.cloudbees.dockerpublish.DockerBuilder.perform(DockerBuilder.java:262)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816)
at hudson.model.Build$BuildExecution.build(Build.java:199)
at hudson.model.Build$BuildExecution.doRun(Build.java:164)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:524)
at hudson.model.Run.execute(Run.java:1897)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:442)
Build step 'Docker Build and Publish' marked build as failure
Finished: FAILURE

Automated Deployement Build Failed in Jenkins

I am doing automated deployemnt in jenkins and getting error saying that:
Build step 'Execute Windows batch command' marked build as failure.
Building on master in workspace:
C:\Program Files (x86)\Jenkins\workspace\AutomatedDeployement1
[AutomatedDeployement1] $ cmd /c call C:\Windows\TEMP\jenkins1993620515430909066.bat
C:\Program Files (x86)\Jenkins\workspace\AutomatedDeployement1>date
The current date is: 08-06-2020
Enter the new date: (dd-mm-yy)
C:\Program Files (x86)\Jenkins\workspace\AutomatedDeployement1>exit 1
Build step 'Execute Windows batch command' marked build as failure
[DeployPublisher][INFO] Build failed, project not deployed
Finished: FAILURE
Your answer will help me in learning. Thanks In advance
The "marked build as failure" message happens because of the exit code in your batch file. Try exit 0 instead of exit 1.
You can also instruct Jenkins to continue building even though there was a build error.

Terraform Jenkins integration - forcing (bypassing) the auto approval process

I am trying to integrate Terraform (to create an AWS instance) with Jenkins and need to force (bypass) the approval process. I am trying to do it as a freestyle job providing the required information under the "Build ENv" section.
I am able to create an AWS instance from Terraform. Now I am trying to automate the process using Jenkins. The job is failing because I am not able to by pass the approval process.
Building in workspace C:\Program Files (x86)\Jenkins\workspace\TerrafromInstancecreation
[ModuleOne] $ "C:\Program Files (x86)\Jenkins\tools\org.jenkinsci.plugins.terraform.TerraformInstallation\Terrafrom_0.12.6\terraform.exe" get -update
[ModuleOne] $ "C:\Program Files (x86)\Jenkins\tools\org.jenkinsci.plugins.terraform.TerraformInstallation\Terrafrom_0.12.6\terraform.exe" apply -input=false "-state=C:\Program Files (x86)\Jenkins\workspace\TerrafromInstancecreation\terraform-plugin\terraform-plugin.tfstate"
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
[1mEnter a value:[0m [0m
Apply cancelled.
FATAL: java.lang.Exception: Terraform Apply failed: 1
at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.executeApply(TerraformBuildWrapper.java:249)
at org.jenkinsci.plugins.terraform.TerraformBuildWrapper.setUp(TerraformBuildWrapper.java:269)
at hudson.model.Build$BuildExecution.doRun(Build.java:157)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
at hudson.model.Run.execute(Run.java:1810)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
I need to force the auto approval process so that the APPLY phase can run through without prompting and then failing.
My sincere request to please provide any scripts / parameters that I need to use . I am performing this as a freestyle jenkins job.
You should use the -auto-approve=true flag when running non interactively. This will also skip the showing of the plan before and just apply out any changes that Terraform deems necessary.

Jenkins, Docker Build Step create image returns NullPointerException

I try to create a job generating a DockerFile and creating a docker image using it, I have installed the Docker Plugin to have such steps
I have a Build Step which should be creating an image like this
However when I run this job, all is fine until a reach this step, which returns me the folowing error
ERROR: Build step failed with exception
java.lang.NullPointerException
at com.github.dockerjava.jaxrs.DockerCmdExecFactoryImpl.init(DockerCmdExecFactoryImpl.java:105)
at com.github.dockerjava.core.DockerClientImpl.withDockerCmdExecFactory(DockerClientImpl.java:64)
at com.github.dockerjava.core.DockerClientBuilder.build(DockerClientBuilder.java:63)
at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder$DescriptorImpl.createDockerClient(DockerBuilder.java:132)
at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder$DescriptorImpl.getDockerClient(DockerBuilder.java:204)
at org.jenkinsci.plugins.dockerbuildstep.DockerBuilder.perform(DockerBuilder.java:68)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
at hudson.model.Run.execute(Run.java:1741)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
Build step 'Execute Docker command' marked build as failure
Finished: FAILURE
I also tried using shell script and running this line
docker build --pull=true -t registry.mywebsite.com:5000/sequoia-$VERSIONBUILD:$BUILD_NUMBER .
but it tells me
docker not found
which means it didn't have Docker, so I need to use the Docker plugin
Is there a problem with my step or is it something with my configuration ?
You need to have the docker service running and the docker binary in $PATH on whichever slave (or master) is running this job.
The plugin simply provides a Jenkins build step to invoke docker as a build step and not the docker service and binary itself. You will need to install and set it up separately.
For more information, please refer the "Configuration" section on https://wiki.jenkins-ci.org/display/JENKINS/Docker+build+step+plugin

Resources