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 get-tools.sh'
                } else {
                    bat 'echo get-tools.sh not implemented for Windows'
                }
            }
        }
    }
}

timeout(time: 23, unit: 'MINUTES') {
    parallel(tasks)
}

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.