I want to execute jenkins pipeline as a administrator - jenkins

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.

Related

Error "$ cmd /c call C:\Windows\TEMP\jenkins6446000872510816227.bat The syntax of the command is incorrect."

Error "$ cmd /c call C:\Windows\TEMP\jenkins6446000872510816227.bat The syntax of the command is incorrect." while executing job for running JMeter test in Jenkins
Going to TEMP folder there was no jenkins6446000872510816227.bat file error aswell. What could be teh issue and what is the solution for this?
Expecting my job build be SUCESS but it is a failure due to this error
Your question doesn't have sufficient amount of details so we cannot troubleshoot your issue.
It's possible to run JMeter script in command-line non-GUI mode like:
c:\apps\jmeter\bin\jmeter.bat -n -t test.jmx -l result.jtl
It's possible to run Windows batch scripts in Jenkins
If it doesn't work for you first check that you can run JMeter test without issues in command-line non-GUI mode on the Jenkins build agent and then double check the syntax of your "Execute Windows batch command" section of the job.
More information: The Complete Guide to Continuous Integration With Jenkins

jenkins job does not finish even though it is successful

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
'''}

protractor integration with jenkins

I need some help in integrating protractor code with Jenkins. I am new to Jenkins so i am not sure if Jenkins or Cruise Control is right as currently we have builds in Cruise Control but we are okay to migrate to Jenkins if that is better. Can someone please help me with any tutorials to link my protractor task with Jenkins or Cruise Control?
Currently we are using Gulp as a wrapper over Javascript code for execution.
We are running it with command Gulp test --site folder name
Should i just specify this command in Execute shell script option of Jenkins?
Yes, running Protractor tests from any CI tool is not complicated
Step 1:Just configure your cruise control/Jenkins job with "Execute Shell" as build step
Step 2: Depending on your choice of running tests .. create a bat file
echo Protractor Execution
Protractor protractor.conf.js // In case running with protractor
npm run --e2etests // In case running with npm run config in package.json
Gulp test --site folder name // In your case
echo Over and out.
Step 3: Point your job build step to trigger the batch file
I got this one worked out. It is working fine when i enter protractor command in Jenkins directly.
I am having some issues with gulp command in jenkins but i will open a seperate thread on that.

Execute a script from jenkins pipeline

I have a jenkins pipeline that builds a java artifact,
copies it to a directory and then attempts to execute a external script.
I am using this syntax within the pipeline script to execute the external script
dir('/opt/script-directory') {
sh './run.sh'
}
The script is just a simple docker build script, but the build will fail
with this exception:
java.io.IOException: Failed to mkdirs: /opt/script-directory#tmp/durable-ae56483c
The error is confusing because the script does not create any directories. It is just building a docker image and placing the freshly built java artifact in that image.
If I create a different job in jenkins that executes the external script as
its only build step and then call that job from my pipeline script using this syntax:
build 'docker test build'
everything works fine, the script executes within the other job and the pipeline
continues as expected.
Is this the only way to execute a script that is external to the workspace?
What am I doing wrong with my attempt at executing the script from within
the pipeline script?
The issue is that the jenkins user (or whatever the user is that runs the Jenkins slave process) does not have write permission on /opt and the sh step wants to create the script-directory#tmp/durable-ae56483c sub-directory there.
Either remove the dir block and use the absolute path to the script:
sh '/opt/script-directory/run.sh'
or give write permission to jenkins user to folder /opt (not preferred for security reasons)
Looks like a bug in Jenkins, durable directories are meant to store recovery information e.g. before executing an external script using sh.
For now all you can do is make sure that /opt/script-directory has +r +w and +x set for jenkins user.
Another workaround would be not to change the current directory, just execute sh with it:
sh '/opt/script-directory/run.sh'
I had a similar concern when trying to execute a script in a Jenkins pipeline using a Jenkinsfile.
I was trying to run a script restart_rb.sh with sudo.
To run it I specified the present working directory ($PWD):
sh 'sudo sh $PWD/restart_rb.sh'

Restarting build steps from the failure point on Hudson/jenkins

My requirement is , Say for example for a job on Jenkins/Hudson , i have configured three build steps which perform 3 separate tasks.
Step1: Execute shell script (echo $PATH)
Step2: Execute Shell Script (sgsh)
Step3: Execute shell Script (echo $JAVA_HOME)
IN these build steps say for example step 2 fails , I need a plugin which will allow me to restart the build from step2 since step1 is already completed successfully. Is there anything available?
Check Conditional BuildStep Plugin . With Run Condition Plugin it do what you want.

Resources