Java API for Jenkins - java

I am writing a Java application where I need to track the status of Jenkins build and execute few actions on build success and failure.
I am quite new to Jenkins. Is there a Java api available to track the status of the build?
Is it possible to trigger the java application on successful completion or during the failure of the build.
Your suggestions are welcome.
Thanks,
Santhosh

There is the Jenkins REST API which could suit your needs
Alternatively, there are literally hundreds of plugins for Jenkins so it is likely that you could run your whole process from within Jenkins using
Build Pipeline
This plugin provides a Build Pipeline View of upstream and downstream connected jobs that typically form a build pipeline. In addition, it offers the ability to define manual triggers for jobs that require intervention prior to execution, e.g. an approval process outside of Jenkins.
Multijob
Gives the option to define complex and hierarchical jobs structure in Jenkins.

Related

Flink cluster on EKS

I am new to Flink and kubernetes. I am planning to creating a flink streaming job that streams data from a FileSystem to Kafka.
Have the flink job jar which is working fine(tested locally). Now I am trying to host this job in kubernetes, and would like to use EKS in AWS.
I have read through official flink documentation on how to setup flink cluster.
https://ci.apache.org/projects/flink/flink-docs-release-1.5/ops/deployment/kubernetes.html
I tried to set it up locally using minikube and brought up session cluster and submitted the job which is working fine.
My questions:
1)Out of the two options Job cluster and session cluster, since the job is streaming job and should keep monitor the filesystem and when any new files came in it should stream it to destination, can I use job cluster in this case? As per documentation job cluster is something that executes the job and terminates once it is completed, if the job has monitor on a folder does it ever complete?
2)I have a maven project that builds the flink jar, would like to know the ideal way to spin a session/job cluster using this jar in production ? what is the normal CI CD process ? Shall I build a session cluster initially and submit the jobs whenever needed ? or spinning up Job cluster with the jar built ?
First off, the link that you provided is for Flink 1.5. If you are starting fresh, I'd recommend using Flink 1.9 or the upcoming 1.10.
For your questions:
1) A job with file monitor never terminates. It cannot know when no more files arrive, so you have to cancel it manually. Job cluster is fine for that.
2) There is no clear answer to that and it's also not Flink specific. Everyone has a different solution with different drawbacks.
I'd aim for a semi-automatic approach, where everything is automatic but you need to explicitly press a deploy button (and not just a git push). Often times, these CI/CD pipelines deploy on a test cluster first and make a smoke test before allowing a deploy on production.
If you are completely fresh, you could check the AWS codedeploy. However, I made good experiences with Gitlab and AWS runner.
The normal process would be something like:
build
integration/e2e tests on build machine (dockerized)
deploy on test cluster/preprod cluster
run smoke tests
deploy on prod
I have also seen processes that go quickly on prod and invest the time in better monitoring and a fast rollback instead of preprod cluster and smoke tests. That's usually viable for business uncritical processes and how expensive a reprocessing is.

Integration Testing against a service in docker

I have a microservice which I am testing (Java maven project with JUnit). This has a dependency on another microservice. I am writing an e-2-e system test and want to spin up the external service from a Docker image for a full automated test.
My question is what is the best way to have a maven project spin up a docker image instance which can then be used in an automated test suite?
At the moment I a using maven-exec plugin to call a shell script during the integration-phase which starts the docker container. It may not be the most elegant solution, and I also have no way of knowing when the container is ready.
Any thoughts or help would be appreciated.
Please note: This is for full system testing against real services so I don't want to mock or stub the external service.
Take a look at Spotify maven plugin for docker or Fabric8 maven pluign
Fabric8 has goals as build, run and stop. This may not help you knowing if a container is ready for testing. (Could you have a sort of ping service in your test code that suspended tests until you got a OK 200?)

How to deploy java web app without creating war file to AWS?

I've been uploading java app to AWS by extracting a war file from eclipse,
But now I've moved my code to github and,
I want to pull it from github onto my AWS server without generating a war file.
I've tried pulling it but it gives me an error. The requested resource is not available.
You can use Jenkins or other CI tool. Jenkins will fetch code from GitHub, compile it and push it to AWS. You only need to specify deploy script.
The CI enthusiast within me suggests to automate the entire thing, going as far as creating an AWS CodePipeline with 3 steps:
(I have three of these pipelines active and am very happy I created them.)
Listen to GitHub repository for changes.
Pull latest repo changes and push code to a Jenkins instance
To save money on the Jenkins instance running 24/7 you could even create AWS Lambda functions to automate the starting up and shutting down of the Jenkins server
Output Jenkins artifact (your war file) to AWS Elastic Beanstalk.
The AWS Documentation as with most services is pretty elaborate on this subject as is Jenkins'. You shouldn't have too much trouble setting this up and it'll save you a lot of time as the WAR file transfer between each step happens on the internal magically-high speed network of AWS.
It will cost some time to set up, especially if you're not that familiar with CI and this process but so very worth it to be familiar with these type of stacks.

How can I start a java program by sending an email

We are working on a project and Im involved in continuous integration testing.
I need to
deploy the new project code on a staging server, not using Jenkins, but ftp;
after the deploy an email is sent to indicate successfull deploy and we need it to start my integration tests;
integration tests, if successfull, will start a deploy on integration server.
I am going to write a java program that will login to Jenkins and execute the integration tests.
Question is: how can the email message activate the java program?
EDIT: Normally, jenkins offers a feature that starts a job after getting an email, but we are having a security problem with that
Make a program or script which will peridically poll a mail server box and upon getting an appropirate email will run another java program.
Please read Jenkins documentation thoroughly. If you are using a version control system, Jenkins can automatically pull the code and run test cases on it. You can notify Jenkins using various methods... including webhooks.
Do go through various plugins for Jenkins.
Update:
I have not used this myself. But looks like this is what you want: Mail Commander Plugin
And the command you send can be something like this:
curl --data '' http://<server>:<port>/job/<projectname>/build

Can I use Jenkins to test to see if a VM(server) is up and running?

Can I use Jenkins to test to see if a VM(server) is up and running? We have alot of VMs(servers) with JBoss, LDAP, MySQL etc on them and I would like to know if I can somehow have Jenkins ping a server to see if the SA shut it down or something..
I was thinking of using a selenium test. I was going to have a Maven project with a selenium java test in it to check of the server is up. but how can I tell Jenkins to run the test every hour and do you think this is the right way to go?
I would say the simplest possible solution is to use Site Monitor plug-in.
It is simple, reliable and it also allows to reuse build status notifications, provided by your jenkins instance. The only limitation is you should have some http server up and running, but I bet you have at least default page available.
Configuration is simple:
Jenkins does not have a plugin for managing (or monitoring) VMs, AFAIK, but you can use Perl or PowerShell for that - both have a good set of tools for that.
Let that tool return error when the server is not available, and you can even use the API to boot a hosted machine.
Cheers

Categories