Running Jenkins on Remote Machine on a specific time ..how? - java

I have few Selenium Java Projects that I wanted to run through Jenkins on a specific time.
I run Jenkins from a remote desktop machine and I start it using command prompt for creating a project / build using
java -jar jenkins.war
and access Jenkins using localhost.
If I wanted to run my projects every day at 6 AM,
Should I have my Virtual Machine where my Jenkins is residing on?
Should Jenkins be running all the time?
Will Jenkins automatically run the build even if it is not running on the Virtual Machine if I make the Build selecting "Run Periodically"?
Please suggest me possible solutions.

Best possible solution is thru Docker+jenkins
Have your dockerfile ready with Run command and steps, which can be done by pulling image in container with necessary config and files and combine with Jenkins server as well, once the run is complete it cleans up the container and it is easy to maintain. All you need is to play with docker to achieve the above scenario.

I don't understand your question complete. Maybe you should improve it a bit.
You access a VM via remote desktop. On this VM you have a jenkins server running. I assume your VM is running 24/7. So no need to ever stop jenkins. And how you confiure your time, you'll find in this answers.

Related

Launching Windows Jenkins Agents without JNLP

Built a new Windows Server 2016 to act as a target for jenkins orchestrated builds. We are not supposed to use oracle java anymore, so I got coretta openJDK. OpenJDK does not support javaws any more. The executable does not ship with it. I have seen some scripted workarounds, but they do not work and are poorly written to boot.
What are we supposed to use to launch slave agents on Windows machines?
There are several ways to implement this but since this is a windows server you can follow steps on https://github.com/kohsuke/winsw/blob/master/doc/installation.md#winsw-installation-guide to install jenkins slave as service without javaws.
I believe #Mike was referring to: Install Slave as a Windows service (cmd version), which does not need JNLP/javaws.
OR, under Jenkins 2 (we are using 2.121.1 plus WMI Windows Agents (aka windows-slaves:1.4), there is now an option to "Let Jenkins control this Windows slave as a Windows service", essentially in the same fashion as a Linux node.
You must have an Admin account (and password). We had to follow the guidance to edit registry when "Windows agents fail to start via DCOM" (Guidance is for Server 2012) to remotely manage the service. So far, seems to be working OK, YMMV. So far, seems to be working OK, no "subtle probelms"; YMMV.
For entries:
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID{72C24DD5-D70A-438B-8A42-98424B88AFB8}
HKEY_CLASSES_ROOT\CLSID{76A64158-CB41-11D1-8B02-00600806D9B6}
(There are several matches for the keys; just change the two locations indicated)
Launch 'regedit' (as Administrator)
Find (Ctrl+F) the following registry key: "{72C24DD5-D70A-438B-8A42-98424B88AFB8}" in
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Wow6432Node\CLSID\
Right click and select 'Permissions'
Change owner to administrators group (Advanced...).
Change permissions for administrators group. Grant Full Control.
Change owner back to TrustedInstaller (user is "NT Service\TrustedInstaller" on local machine)
Repeat the steps 1-6 for HKEY_CLASSES_ROOT\CLSID{76A64158-CB41-11D1-8B02-00600806D9B6}
Restart Remote Registry Service (Administrative Tools / Services)
For me the easiest and best working solution to launch Windows Jenkins Agents without JNLP was to run in the command prompt java -jar agent.jar ... command. The command parameters should be grabbed from the url of the agent:
http://your_jenkins_url/computer/your_agent_name_or_ip/
I downloaded the agent.jar on my PC, moved it to a desired directory, launched the Command Prompt from the dir where the agent.jar was moved and executed the proposed command with the appropriate parameters.
In my case:
java -jar agent.jar -jnlpUrl http://your_jenkins_url/computer/your_agent_name_or_ip/slave-agent.jnlp -secret 76986574e97c2b635c7076740dc93326eaaf5a3ad30573144915489a1ccfee44 -workDir "D:\jenkins"
This was one of the proposed approaches in the docs here - https://www.jenkins.io/doc/administration/requirements/upgrade-java-guidelines/
Java Web Start Java Web Start has been removed in Java 11. When a
Jenkins controller is running on Java 11, the Java Web Start button
will no longer appear in the Web UI. Agents for a Java 11 Jenkins
server can’t be launched from a *.jnlp file downloaded to a web
browser.
There are no plans to replace this functionality. Connect agents to
Jenkins on Java 11 with plugins like SSH Build Agents Plugin, with
operating system command line calls to java -jar agent.jar, or by
using containers.

How to run a Java application on Ec2?

I want to deploy a a project to ec2. It was modify in Intellij which used MAVEN. It work perfect in Intellij. Below is the configuration of Intellij.
I have tried command line like java, javac. These kind of comment lines are all failed. I am wondering there must some way to convert Intellij configuration to command lines. I was relying too much on IDE. XD. Now I am regreted.
EC2 is the amazon cloud service for instances. If you aren't very experienced with it - the easiest you can do is to hire a machine with your fav operating system - for example Windows and use remote desktop to log in it and just do your normal IDE setup and run your app. You will have your app running on your instance and it will be working, even it is done the hard way. I will get downvotes for that, but it will work as a Swiss watch.
It depends from the kind of EC2 instance you're using.
For me would be simpler if it was a Linux instance.
I'll connect via ssh and git clone my project there from my bitbucket/github repository.
Then I'll use Maven, and there are many different options to run your project with Maven.
As suggested in the comments you could use the exec plugin.
But even in this way you'll have a list of problems to overcame.
For example your linux instance does not came with an preinstalled Java Runtime.
You have to install at least Java and Maven (choose ubuntu distro, so you can do easily with a package manager like apt-get).
Or, for example, another not easy task is connect via ssh to a Linux instance.
AWS generates a key.pem file that you have to use in order to successfully connect to your instance.
ssh -i .ssh/your-key-file.pem username#your-ec2-instance-address
And again, AWS does not tell you the name of the default user you must use to connect to your EC2 instance (if you choose ubuntu distro the username is ubuntu).
And again, when you save your-key-file.pem in your computer it must have the right permission
-rw-------# 1 freedev staff 1692 Apr 21 09:46 /Users/freedev/.ssh/your-key-file.pem
or your ssh client wont read it.
...looking back it was really a long way make a deploy on a EC2 instance.
I have solved it by myself.
Use mvn package to generated jar file for maven project.
nohup java xx.jar debug.xml & use this to run jar in shell. By using this command line, when exit (abort remote connection), the process / command will not get killed.
Command line jcmd is used to check running process pid.

Steps to deploy play framework application to production environment?

I got stuck in the steps to deploy the play-java application to standalone server. I am using Ubuntu instance running onEc2 machine. After reading the official documentation I followed these steps:
Install typesafe activator to $Home/activator
Copy my project folder to $Home/activator/projects using Jenkins
Run cd $Home/activator/projects/project
Run dist command. It generate the project sh file
Run cd $HOME/activator/projects/sample/target/universal. It shows me three things i.e. sample-1.0.zip , tmp.
Run unzip sample-1.0.zip
Run cd $Home/activator/sample/target/universal/sample-1.0/bin. It shows me two scripts i.e. sample (for mac and linux) and smaple.bat (for windows).
Now, I tried to run this command as documentation says: sample-1.0/bin/sample -Dplay.crypto.secret="abcdefghijk" but it got stuck and shows nothing except a prompt on terminal.
What next steps are required to run the application in daemon mode. So that server will continue to run always?
Another question is why do I need to follow these steps because just after copying the project I can easily run activator run command to sample folder to run the server.
EDIT-1
Now I am getting Error: Could not find or load main class play.core.server.ProdServerStart while running sample -Dplay.crypto.secret="abcdefghijk" command
Play Framework modes
Play like other frameworks can run in different modes because we are usually like to run our program in different situation and these situations need their configuration. Production is one of play modes. In this mode as the name suggested we are ready to deploy our application where user can use.As a result requirements are different.
Some common configuration in Production mode :
We are confining https
Using production data base not testing one
Play doesn't show errors
Play framework run as long term process and if you are log out of your server your application will run
If your app fails Play will clone another application and run that so your app run forever except you turn it off.
and so on (it is based on your Production config file)
Your answer :
If you just want to test your app in remote server and see what happened, it's okay to use activator run this command runes Play app in development mode and application will killed if you exit or log off (error will shows up and so on). But if you want to use your app for Production it is necessary to run all of these steps.

Running exe files with Hudson on Windows 8

I am attempting to have a Hudson job run a windows executable on a Windows 8 VM. When I attempt to run the exe file I get the error:
java.io.IOException: Cannot run program "C:\hudson\workspace\workspaceName\installer\bin\fileToExecute.exe": CreateProcess error=740, The requested operation requires elevation
Has anyone run into this and had it run automatically? I can't just have the exe file on the VM and set its permissions because a new copy gets downloaded at the start of each build.
Thanks in advance.
Disclaimer: I have not tried this with Windows 8.
First things first, even if you succeed to launch an .exe application from Hudson/Jenkins, it will be running under a different session, probably invisible to you. I've managed to achieve the workarounds for this with PsExec as detailed here:
Open Excel on Jenkins CI
With the above method, you will be able to launch an application and actually see it in the logged in session.
If your application does require elevated permissions for whatever reason, you've got to add -h switch to PsExec

How to run Java application on startup of Ubuntu Linux

I have a requirement where I need to develop application that reads TCP/IP Socket. I successfully made the program as Java program with No GUI means as soon as program runs it starts listening to the Socket and gets the response with the help of Netbeans IDE. Now as per my requirement i have to start execution of this program as soon as Linux system Booted.
Actually I am very novice in Java and Linux Platform, so have few doubts..
Is my Socket Program with no GUI is fine to be run as per my requirement.
How can I write script to run jar on Linux Boot up, I got to know. init.d is meant for this.
Ideally you should create a service wrapper for your java application and then make this service run on startup example here.
Use
sudo update-rc.d mytestserv defaults to run your service wrapper on startup on Ubuntu
So two things you'll need to do:
First create a small shell script to start your java program from a terminal. As you have packaged as a jar have a look at this, specifically the JAR Files as Applications section.
This may be sufficient: (although you'll want to use the full path to Java)
#!/bin/bash
java -jar path_to_jar_file
You should be able to run your script and successfully start your program.
Once you've got it starting from a script you can use standard linux tools to start the script. Either putting it in /etc/rc.local, or as you're using Ubuntu, use update-rc.d to start it on boot. See here for a very simple example of using update-rc.d
Hope this helps,
Will

Categories