jenkins job does not finish even though it is successful - jenkins

I have a Jenkins pipeline job in which I give a windows batch command to start my hybris server. Normally also if hybris is started from a command prompt, the server window (command window) will keep the process running and it does not exit. With the same thing happeining in Jenkins, the job never ends even though the server has successfully started. Pls suggest how I can get the server running, yet exit out of the job succesfully. Below is the pipeline script:
node {
stage 'ServerStop'
echo 'Stop the server if previously running'
bat '''call D:\\path_to_hybris\\hybris\\bin\\platform\\hybrisserver.bat stop
EXIT /B 0'''
stage 'Checkout'
echo 'Checkout related script'
stage 'Build'
echo 'Build script here'
stage 'ServerStart'
bat '''call D:\\path_to_hybris\\hybris\\bin\\platform\\start.bat
'''}

Related

I want to execute jenkins pipeline as a administrator

I want to execute jenkins pipeline as a administrator
or
I want to execute pipeline with specific cmd.exe.lnk that I setup 'run as administrator' option.
Also, When I tried to build below windows command, I can't watch the build log on console output.
[ windows command sample ]
- start (PATH)\cmd.exe.lnk /k "cd (PATH)\mvn clean package"
And,
I already tried to build with bat file that setup 'run as administrator' option.
but It was also just finished as 'success' but nothing to happen for me.
Please, let me know how should I do in this situation.

How to Direct the Cmd line output to jenkins

Stage("execution") {
Steps {
bat 'start cmd.exe /c c:\\users\\doc\\sample.bat'
}
}
The above script is just opening the cmd prompt and executing it. It's not taking the output of the execution. Even if the execution fails, the stage is shown as successful and it moves to the next stage for deployment. I want to develop it so that the output in the cmd prompt should be taken as input by Jenkins and stage should go on. If the stage fails during execution, the stage should show failure and if the execution succeeds, the stage should show success in Jenkins. Can anyone help?
Another question: If the batch file is located in Git, how to give the path in the above script?
Using the start command, you are creating a new detached console process which Jenkins cannot keep track of.
Do it like this instead:
bat 'call "c:\\users\\doc\\sample.bat"'
This runs the batch file in the same environment as the current script and waits for the batch file to end. Jenkins will be able to capture the standard output and detect errors through the exit code of the batch file.
You may write #call to hide the command-line from the output.

Jenkins delivery pipeline view -how to add manual trigger(play button)?

I am trying to connect/achieve below things:
Pipeline having job with multiple stages and tasks
Configure above pipeline with Delivery view plugin
Last task of last stage is to deploy to production [caution: want this task with manual trigger]
Jenkins version: 2.222.x
Things I tried
node {
stage 'Build'
task 'Compile'
echo 'Compiling'
sleep 1
task 'Unit test'
sleep 1
stage 'Test'
task 'Component tests'
echo 'Running component tests'
sleep 1
task 'Integration tests'
echo 'Running component tests'
sleep 1
stage 'Deploy'
task 'Deploy to UAT'
echo 'Deploy to UAT environment'
sleep 1
task 'Deploy to production'
echo 'Deploy to production, but wanted with manual trigger'
sleep 1
}
Below is the desired configuration which I am looking.
desired configuration, delivery pipeline plugin wiki
I could able to achieve that manual trigger by creating multiple free style jobs with upstream and downstream configuration and for the manual step I can set post build job with manual trigger.
But that is something which I want in pipeline because there we have task (inside stage also we can do separate vertical tasks)feature.
Please help me and suggest how to achieve this.

Jenkins job status failing despite running correctly

I have a jenkins jobs that executes with 'Publish over SSH'. The job connects to the remote server, transfers files and runs and ansible playbook.
The playbook runs as intended, confirmed by the logs. However at the end of the job an error is returned, failing the job. It's causing problems as it's preventing the pipeline from working correctly.
SSH: EXEC: completed after 402,593 ms
SSH: Disconnecting configuration [server] ...
ERROR: Exception when publishing, exception message [Exec exit status not zero. Status [2]]
Build step 'Send files or execute commands over SSH' changed build result to UNSTABLE
[Run Playbook] $ /bin/sh -xe /tmp/jenkins1528195779014969962.sh
+ echo Finished
Finished
Finished: UNSTABLE
Is there a setting missing to allow this to pass?
never used the 'Publish over SSH' you are referingto, but I can recommend Jenkins Ansible Plugin. I am running several playbooks in pipeline stages here successfully from labeled build slaves (have one dedicated slave that has Ansible installed) targeting Linux hosts on cloud infrastructure via SSH.
Especially in combination with the ANSI color plugin the output very readable.
If you cannot try that plugin, check whats the return code of the playbook run shell call.

How to wait for job to finish when using jenkins-cli.jar to run a slave job?

I have a Jenkins slave ( at localhost:8000 ) and I am executing it ( link ) from a Jenkins Master ( at localhost:8080 ). The basic idea here is to run the remote job and wait until the job is finished.
java -jar jenkins-cli.jar -s http://localhost:8000 build "Test Suite"
Right now, this doesn't wait. I starts the job on the slave and the Jenkins Master says the task is immediately finished although the slave runs for another 30 minutes.
Does anyone know how I can block or check for a signal on the slave to verify it is finished and get the exit status code of the job?
NOTE: My slave test MUST run on the slave because it won't run from Jenkins master, which runs as a service and doesn't allow permissions to start a webbrowser from the test. So, I run the slave in a visible console.
java -jar jenkins-cli.jar -s http://localhost:8000 build "Test Suite" -s
Adding the parameter -s to the build command should trigger the job and return after job is completed
Each windows application returns an exit code to it's parent. Examine the exit code using a windows batch file. Example:
java -jar jenkins-cli.jar -s http://127.0.0.1:9090 build "Test Suite" -s
echo The exit code is %errorlevel%
On successfull job completion you will get:
Completed "Test Suite" #72 : SUCCESS
The exit code is 0
Examine some error scenarios (wrong job name, job creates FAILED and so on)
Note: Running master jenkins not as windows service may be more easy.

Resources