deploy jar on windows server with jenkins pipeline - jenkins

I have a maven built jar file which could be run as a server. I want to use jenkins-pipeline to deploy this jar file onto my windows 2016 server. I started with a freestyle jenkins job, with "Execute Windows batch" configuration:
set BUILD_ID=DontKillMe
start java -jar MyServer.jar
The java process successfully spawned on my windows 2016 server.
When I turned to use jenkins pipeline script with same batch commands, it's not as expected -- the process which should contain java -jar MyServer.jar was never spawned.
The pipeline script I wrote is:
bat '''
set BUILD_ID=DontKillMe
start java -jar MyServer.jar
'''
The reason I want to have jar starts running in another process is that it could release current jenkins build to following steps.
Could anyone please help with a solution? As long as I can spawn up the java process from batch command in jenkins pipeline (better with no parent process), I would be really grateful.

Ok, seems like jenkins is trying to abandon old jenkins users like me, here's the solution provided by jenkins pipeline:
withEnv(['JENKINS_NODE_COOKIE=DontKillMe']) {
bat "start java -jar MyServer.jar"
}

Related

Jenkins Ranorex plugin not executing test

I am new to Jenkins. I have master and slave configuration done and I have installed Jenkins on my master and want to run my ranorex test on my slave machine. All files needed for running ranorex scripts are present on my slave. When the job from the master runs, it gives error
[2019/11/18 17:04:51.686][Debug ][Logger]: Console logger starting.
[2019/11/18 17:04:51.845][Failure][TestSuite]: This operation requires an interactive window station
[2019/11/18 17:04:51.858][Debug ][Logger]: Console logger stopping.
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
i tried workarounds like going to Jenkins serve and selection option of user interaction.
If i only have bat file on slave of copying one folder to another and if i trigger job from master, it works. So master slave configuration does not have issue. Issue is running Ranorex GUI Test on Slave.
Jenkins needs to be running as an application not a service (which is default). Services cannot show anything with a GUI nor interact with anything with a GUI.
Disable the Jenkins service
Run Jenkins via Command Line java -jar jenkins.war
For a more detailed guide, check out the Infrastructure section of the Ranorex Jenkins integration blog.

Running jobs in Jenkins slave node using Groovy script

I am confused about whether a Jenkins job can be run using Groovy script in the slave node. I referred a StackOverflow answer [1] which says that System Groovy script jobs can be run in master and not in slave, and to run a job in slave it has to be Groovy script rather than System Groovy Script. Can someone clarify me whether we can run a slave job using System Groovy Script? Since I am trying through Groovy script I am unable to access few Jenkins instances. Please suggest me a better way with an explanation. Thanks in advance
I have finally found that it is only possible to run jobs in Jenkins slave node using Grovvy script. The system groovy script runs inside the Hudson master's JVM. Thus it will have access to all the internal objects of Hudson, so we can use this to alter the state of Hudson. It is similar to the Jenkins Script Console functionality.

Jenkins plugin to copy files to windows server

I have a situation where in I need to copy set of files to a windows server through Jenkins. I see a lot of Jenkins plugins that will do this kind of job through ssh but not in my case. Jenkins is also hosted in a windows server and end server is also a windows, so I believe ssh is not an option. Any plugin available in the market to get the job done or writing our requirements in powershell/MSDos script is the only option?
Thanks in advance!
just execute a bat command with the following
copy C:\localfile.bak \\remotemachine\c$\Path\remotefile.bak
in the Using the Execute Windows batch command option in the build Step
How to run bat file in jenkins

Call Jenkins CLI from within pipeline

Is it possible to call Jenkins CLI commands within a pipeline?
Upon migrating jobs to new Jenkins instances I would like to enable users to migrate their own jobs from an old Instance.
Yes, you can write pretty much any shell code you want, including calling the CLI jar from a shell instruction.
sh "java -jar /path/to/jenkins-cli.jar your-usual-command"

Executing shell script using Jenkins UI

I would want to execute the shell script using Jenkins.
For example, I have a shell script MakeTest.sh which is on the server "test1.test2.net" location "/home/rt", how would I execute it? My Jenkins and script to be executed are in different servers.
Thanks!
Using git, you can download the file into the workspace of your job.
After you just have to launch the script ./MakeTest.sh

Resources