Jenkins Jobs are not loading while starting it from CLI - jenkins

I have setup a lot of jobs while Jenkins is running as windows service.When i try to start Jenkins from command line , none of the jobs are showing up.
Can some one let me know how to make sure all jobs are loaded when i start Jenkins from CLI on windows machine.

Make sure you have the same Jenkins home directory when you run it from CLI.
You can use JENKINS_HOME variable to control that:
set JENKINS_HOME=C:/myJenkins
java -jar jenkins.war

Related

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

deploy jar on windows server with jenkins pipeline

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

how to launch jenkins with previous jobs

I shutdown jenkins for some purpose. Wonted to launch the jenkins from previous workspace. is there a way to restore the same old jobs?
I am starting jenkins like
java -jar jenkins.war --httpPort=8083 &
But is there a way to provide workspace from commandline?
Workspace is a specific term related to jobs in Jenkins. I think you are looking for JENKINS_HOME. Set the environment variable to the path to the directory that has all your jenkins config and jobs before you start Jenkins.

How to start Selenium in a Jenkins job

I am using Jenkins and Ant to execute my Selenium tests. I would like to make a job that would do the following:
starts Selenium server
executes tests and
kills Selenium server after all tests are run.
I am able to start the Selenium server manually with the following command:
java -jar selenium-2.16.1\selenium-server-standalone-2.25.jar
But I cannot find a Jenkins plugin that would do the start/stop for me. All I can find are some Selenium reporting plugins.
Not sure if there is a plugin, but you can just run the launch and kill commands via the Jenkins job.
Under Build, if you add an Execute shell build step, you can run your commands from there.
Note - The path to the selenium server is relative to the current work directory.
Looking at your error trace, looks like you are running this on a windows PC. you need to be running this as a "execute windows batch command" then run java -jar selenium-2.16.1\selenium-server-standalone-2.25.jar Assuming that you have your jar file on the workspace. or you beed to point it at the right path

launch-slave script

according to the jenkins wiki
/var/jenkins/bin/launch-slave is a shell script that Jenkins uses to execute jobs remotely. This shell script sets up PATH and a few other things before launching slave.jar. Below is a very simple example script
I'm running jenkins as JNLP and don't have a /bin, so I'm not sure where should i put this file
Run Jenkins 'headlessly', not via a browser:
java -jar slave.jar -jnlpUrl http://[jenkins_server]/computer/[slave-name]/slave-agent.jnlp
Write a script containing that command and add whatever else you want before it, including setting the new PATH.
You can also specify environment variables (or 'key-value pairs') in the slave node configuration. Navigate to http://[jenkins_server]/computer/[slave-name]/configure and check off 'Environment Variables' check-box.
The script on Jenkins wiki you refer to is meant as an example for those who want to use slaves of type "Launch slave by executing a command on master". If you are using JNLP type slaves, then you don't need this script.
What you need to do is log onto the slave machine, open the web browser to your Jenkins, navigate to the page of your slave and hit the orange button. Or use one of the command lines on the page to run the slave.

Resources