Deploy to Linux and Windows with tomcat

Thank you very much for the prompt response Mark, you have saved me the time of continuing down the Blue Ocean path.
On the other hand, I need something simple, and I would like to please, although I understand that it is not part of the thread, if you can give me a simple answer.
What I need is for Jenkins to check every x time if there are changes in the controller of a repository, if there are, to deploy that code to different machines, both Linux and Wibdows with tomcat (the part of all the stop instructions tomcay and copy the new .wars and start tomcat I would do it with Ansible)
What is the best option of all that Jenkins offers to do something like this?
Thank you so much

You’ll have a better experience if you configure your repository to notify Jenkins whenever there is a change. That is usually done with webhooks. In many cases, an organization folder or a multibranch Pipeline may configure those webhooks automatically. You want to avoid polling for changes. As advised by Kohsuke Kawaguchi in 2011, “polling must die”.

If it were me, I’d create a command line script or program in my favorite scripting language. Once that command line script is working, I’d add a Jenkinsfile that calls the script. If the script needs credentials, have the Jenkinsfile pass them in using withCredentials.

I’d keep the Jenkinsfile as short and simple as possible because it is a lot easier to debug deployment failures from a development environment on my desktop than to repeatedly run the Jenkins job to debug failures.

1 Like

Once again, thank you very much for the response Mark.
I understand what you are saying, but I don’t have to deploy only on one server, but on dozens of servers, both Linux and Windows, therefore we already have Ansible in production.
My simple question was, what method is best within Jenkins to do this one that I mentioned in the previous post…pipeline? which?
Thank you so much

When I need to deploy new software to multiple servers, I define a Pipeline job that runs a script in parallel on all the servers. I’m not sure if that’s what you’re asking, but the job definition that I use is:

def nodes = nodesByLabel label: 'jagent && !windows'
nodes = nodes.sort()

Map tasks = [:]

for (int i = 0; i < nodes.size(); i++) {
    def label = nodes[i]
    def stageName = 'Get tools ' + label
    tasks[label] = {
        node(label) {
            stage('start') {
                echo 'placeholder stage for graph view'
            stage(stageName) {
                checkout scm
                if (isUnix()) {
                    sh 'bash'
                } else {
                    bat 'echo not implemented for Windows'

timeout(time: 23, unit: 'MINUTES') {

That defines a job that runs on all the non-Windows agents connected to my controller at that moment. They all run that script. It checks out a repository and runs the script from the repository. That particular script is used to deploy to CentOS 7, Debian 10, Debian 11, Debian 12, Debian testing, Debian unstable, FreeBSD 13, Red Hat 8, Rocky 9, Ubuntu 20, and Ubuntu 22.

1 Like

Once again, thank you very much for the response Mark.
Yes, that is partly what I am asking, only that “in the middle” of this execution comes Ansible. As I told you in my previous message, Ansible is in charge, through a defined playbook, of connecting to each server, be it Windows or Linux, to tomcar, delete the old .war file, upload the new one that it has detected in the Bitbucket repository, and start the tomcat again.
I understand that you know Ansible, since it is one of the best-known automation software.
I got the idea from here… (you must translate it into English hehe)
Thank you so much

Since Ansible is in charge of connecting to each server and performing the operations, then it should be enough in the Jenkins job to checkout the Ansible playbook on an agent that has Ansible installed then run Ansible with that playbook.

In your case, the script that calls Ansible is the command line script that I mentioned earlier.

I don’t know Ansible. I’ve not yet used it in a production environment.

1 Like

Good afternoon Mark, excuse my ignorance. But it is not at all clear to me how with the classic Jenkins interface, I can get to the result I want to obtain.
Even reading the documentation I am not clear.
The summary of what I need is what I mentioned before. I simply need Jenkins to check a Bitbucket repository every x time, when there are changes in that repository, compile that code into a .war, and upload it to certain endpoints, both Linux and Windows. Before performing the action for tomcat, delete the old file and add the new one.
I still don’t know if I will do this process with Ansible, although the idea is that it will, but to summarize, I don’t understand the Jenkins interface in pipeline where:

-Where do I add the connection with Bitbucket in the pipeline interface?
-Where do I tell Jenkins the frequency that I want him to verify the repository, whether there are changes or not?

I think that by solving these two main things we can move forward.
Thank you so much.

You define a multibranch Pipeline using the Bitbucket branch source plugin.

A tutorial video on multibranch Pipeline is available at:

Don’t tell Jenkins the frequency to verify the repository. Let Bitbucket notify Jenkins when there is a change. I believe that the Bitbucket branch source plugin. will configure that notification from Bitbucket to Jenkins automatically.

1 Like

Hi Mark.
I’m sorry to bother you again, but after reading, watching and studying every video and tutorial, I’m still not sure how to deploy a correct architecture in Jenkins to satisfy what I need.
I have made a diagram so that you can better understand what I need.
I have seen the multibranch video, and I still don’t understand if it is really what I need for my Jenkins implementation.

I detail the questions and answers I have about each point in the outline.

  1. In this phase of the scheme there is no doubt or problem, since the developers upload the code of their version to the main branch of the repository.

  2. How do I configure Jenkins to detect the change in a specific branch, in this case in main? I understand that I have to upload a Jenkins file to this main branch?
    What option should I choose for this? pipeline?

  3. In which part of the pipeline, if this is the best option, and how, I tell Jenkins to include the Maven libraries to compile the code into the final .war file that must be sent to the different servers in production?

  4. This is the point that I am least clear about, how does Jenkis know which host to connect to? where the SSH credentials of each host and the respective IP’s are included?
    In case you are clear about the connection issue, I understand that through a script in the case of Linux, I can give you instructions in one of the stages to stop the tomcat, delete the files within …/ webapps and then start them again.
    Where should the scripts be?
    And in the case of Windows?

Thank you very much for everything and sorry for the inconvenience.

Good afternoon everyone. Could someone help me on how to implement something like what I describe in the diagram? I don’t want anyone to do the work for me, just some tips on the most efficient way to implement something like this.
Thank you so much.

Hi community.
In order to simplify the implementation of this project, I need to start with something simpler, and that is, understand how to connect my Bitbucket repository in a simple job and as point number two, what pugin should I use so that when my Jenkins I want to compile the code, Can I call the libraries that I have on a Maven/Sonatype server?
Thank you

Hi Mark, I hope I don’t bore you with the same things.
I have managed to access the repository and configure the integration with Slack, I am doing it all in a simple job, to make it less complex I have added “layers” of tasks in terms of what I need.
Now I need the code compilation part, that Jenkins “downloads” the code from the repository, connects to my maven server where the libraries are hosted, compiles and generates a final .war file to be sent to the end points.
I’m not sure if I need a Maven plugin to make Jenkins request the necessary libraries to compile from the Maven server?
Thank you.