<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nivaldo Melo on Medium]]></title>
        <description><![CDATA[Stories by Nivaldo Melo on Medium]]></description>
        <link>https://medium.com/@nivaldogmelo?source=rss-306cb82a4497------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*c7ht7TQU3ulzIhHfB8A3wQ.jpeg</url>
            <title>Stories by Nivaldo Melo on Medium</title>
            <link>https://medium.com/@nivaldogmelo?source=rss-306cb82a4497------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 23:00:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nivaldogmelo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Structuring a Terraform project Pt.1]]></title>
            <link>https://medium.com/@nivaldogmelo/structuring-a-terraform-project-pt-1-3768244800f1?source=rss-306cb82a4497------2</link>
            <guid isPermaLink="false">https://medium.com/p/3768244800f1</guid>
            <category><![CDATA[terratest]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Nivaldo Melo]]></dc:creator>
            <pubDate>Tue, 13 Aug 2024 21:02:58 GMT</pubDate>
            <atom:updated>2024-08-13T21:02:58.863Z</atom:updated>
            <content:encoded><![CDATA[<p>As we know, Terraform is one of the most popular tools when we talk about declarative Infrastructure as Code (IAC). However, one aspect that often feels a bit unclear for me is how to structure projects effectively. While it’s easy to find tutorials on best practices for naming resources, figuring out the right folder structure can be more challenging. Should you use modules? Workspaces? How much should you aggregate resources into a single .tf file?</p><p>To address these questions, I decided to create a structured module that I could use across my projects. This structure includes functionalities that I consider essential. The module is built on four key pillars:</p><p>- <strong>Modules</strong>: These are used to group related services that function as a unit, reducing code repetition and improving maintainability.<br>- <strong>Examples</strong>: This section contains use case examples to make it easier for teams to adopt this structure.<br>- <strong>Unit Tests</strong>: These help us detect failures early in the development process.<br>- <strong>Documentation</strong>: We’ll aim to make the documentation process as seamless as possible, so it doesn’t become a burden during development.</p><p>Let’s start by exploring why these pillars are important.</p><h4>Modules</h4><p>As many of you know, a module in Terraform is a way to increase code reusability by aggregating resources that are often created together. By doing this, you can centralize configuration in a single file, making bulk changes easier and more efficient. It’s important to remember that when you’re writing modules, other people might depend on your code. Therefore, it’s crucial to be mindful of this before making any breaking changes.</p><h4>Examples</h4><p>All examples should have a practical use case, making it easier for readers to see how they can be applied in their own environments.</p><h4>Unit Tests</h4><p>Testing infrastructure can be uncommon due to potential costs, but when done in a controlled environment, it greatly simplifies development and maintenance. Through tests, we can describe the most important scenarios that the module should cover, helping to prevent unwanted breaking changes. Another advantage is that by documenting these scenarios, we don’t have to rely on someone remembering to manually test everything, which can lead to errors.</p><h4>Documentation</h4><p>Last but not least, there’s the documentation. Good documentation makes it easier for teams to understand and adopt your product. However, if done manually every time, it’s easy for things to become outdated, leading to inaccurate and difficult-to-follow documents. That’s why we aim to make the documentation process as seamless as possible, ensuring that it always stays up to date with the project’s code.</p><h3>Final look</h3><p>So to have an idea of what we’re aiming to, this is the repo structure that we’re aiming to have in the end. You may notice that we have some <em>.go </em>files, it’s because we’re gonna use a tool written in golang to write our tests</p><pre>terraform-modules-structure<br>├── examples/<br>├── go.mod<br>├── go.sum<br>├── modules/<br>├── README.md<br>└── test/</pre><h3>Writing your code</h3><p>Before we start, let’s define the kind of service we’re going to write. For this example, we’ll create a Cloud Function on GCP. In a Cloud Function, there are multiple ways to store your source code; in this example, we’ll use a GCS bucket.</p><h4>Initializing the Repository</h4><p>This part is straightforward; we just need to start a Golang project, which can be done as follows:</p><pre>❯ mkdir terraform-modules-structure &amp;&amp; cd terraform-modules-structure<br>❯ go mod init terraform-modules-structure</pre><p>Note that I’ve named my project <em>terraform-modules-structure</em>, but you can name it whatever you like.</p><h4>Examples</h4><p>This is arguably the most important phase of the project. Here, we’ll define the module’s use cases, thinking like a final user. Therefore, the examples need to be clear, practical, and stable; otherwise, adoption of the project might be compromised.</p><p>As end users, we need to create a Cloud Function in GCP. Let’s start by considering which parameters we should control and which ones we shouldn’t.</p><blockquote>Looking at this <a href="https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloudfunctions2_function#example-usage---cloudfunctions2-basic">example</a>, we’ll propose that the user can control the following parameters:<br>- function name<br>- region<br>- description<br>- runtime<br>- entry_point<br>- max_instance<br>- memory<br>- timeout</blockquote><p>Other parameters can be defined within the module itself, including the connection to the bucket.</p><h4>Terraform files</h4><p>So let’s start creating this files</p><pre>❯ mkdir -p examples/gcp/cloud-function-v2<br>❯ touch examples/gcp/cloud-function-v2/main.tf</pre><p>In <em>main.tf</em> let’s write:</p><pre>module &quot;function&quot; {<br>  source = &quot;../../modules/gcp/cloud-function-v2&quot;<br><br>  name        = &quot;my-function&quot;<br>  description = &quot;My function&quot;<br>  region      = &quot;us-central1&quot;<br><br>  runtime     = &quot;nodejs16&quot;<br>  entry_point = &quot;helloGET&quot;<br><br>  source_path = &quot;./src&quot;<br><br>  max_instances = 1<br>  memory        = 256<br>  timeout       = 60<br>}</pre><h4>Deploying the source code for the function</h4><p>Let’s create the function so that we’re able to deploy it. To do this, follow the example in the official Google documentation. To fit it into our structure, you just need to do the following:</p><pre>❯ mkdir examples/gcp/cloud-function-v2/src<br>❯ touch examples/gcp/cloud-function-v2/src/index.js<br>❯ touch examples/gcp/cloud-function-v2/src/package.json</pre><p>and then fill the <em>index.js</em> with:</p><pre>const functions = require(&#39;@google-cloud/functions-framework&#39;);<br><br>// Register an HTTP function with the Functions Framework that will be executed<br>// when you make an HTTP request to the deployed function&#39;s endpoint.<br>functions.http(&#39;helloGET&#39;, (req, res) =&gt; {<br>  res.send(&#39;Hello World!&#39;);<br>});</pre><p>and <em>package.json</em> with:</p><pre>{<br>  &quot;name&quot;: &quot;nodejs-docs-samples-functions-hello-world-get&quot;,<br>  &quot;version&quot;: &quot;0.0.1&quot;,<br>  &quot;private&quot;: true,<br>  &quot;license&quot;: &quot;Apache-2.0&quot;,<br>  &quot;author&quot;: &quot;Google Inc.&quot;,<br>  &quot;repository&quot;: {<br> &quot;type&quot;: &quot;git&quot;,<br> &quot;url&quot;: &quot;https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git&quot;<br>  },<br>  &quot;engines&quot;: {<br> &quot;node&quot;: &quot;&gt;=16.0.0&quot;<br>  },<br>  &quot;scripts&quot;: {<br> &quot;test&quot;: &quot;c8 mocha -p -j 2 test/*.test.js --timeout=6000 --exit&quot;<br>  },<br>  &quot;dependencies&quot;: {<br> &quot;@google-cloud/functions-framework&quot;: &quot;^3.1.0&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br> &quot;c8&quot;: &quot;^8.0.0&quot;,<br> &quot;gaxios&quot;: &quot;^6.0.0&quot;,<br> &quot;mocha&quot;: &quot;^10.0.0&quot;,<br> &quot;wait-port&quot;: &quot;^1.0.4&quot;<br>  }<br>}</pre><p>Great! Now we have a use case, so let’s document it.</p><h4>Documentation</h4><p>Now that we have a use case, it’s important to make it easy to adopt by providing a README that explains how to use it. For this, we’ll use <a href="https://terraform-docs.io/user-guide/introduction/">terraform-docs</a>. After installing it, we’ll set up the following:</p><p>First, create the <em>examples/.terraform-docs.yml</em> file, which will serve as the base structure for all the examples:</p><pre>formatter: &quot;markdown table&quot;<br>header-from: header.md # Specifies the source for the README header content<br><br>content: |-<br>  {{ .Header }}<br><br>  ```hcl<br>  {{ include &quot;main.tf&quot; }}<br>  ```</pre><p>Next, create the<em> examples/gcp/cloud-function-v2/header.md</em> file to define a header specific to our example. For this case, the content might be:</p><pre>## Creating a Cloud Function<br><br>This example demonstrates how to create a Cloud Function in GCP using Terraform. The example will zip the code inside the `src/` folder and store it in a GCS bucket.</pre><p>Finally, run the following command to generate your README:</p><pre>❯ cd examples/gcp/cloud-function-v2<br>❯ terraform-docs -c ../../.terraform-docs.yml .</pre><p>With this we have a documented use case and provide a process to regenerate it based on your code. To automate this process, simply add it to your CI pipeline.</p><h3>Next steps</h3><p>In the next part of the series, we’ll write a unit test based on our example.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3768244800f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Simple Port Scanner with GO]]></title>
            <link>https://medium.com/@nivaldogmelo/building-a-simple-port-scanner-with-go-6505374e2bc4?source=rss-306cb82a4497------2</link>
            <guid isPermaLink="false">https://medium.com/p/6505374e2bc4</guid>
            <category><![CDATA[port-scan]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[port-scanning]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[goroutines]]></category>
            <dc:creator><![CDATA[Nivaldo Melo]]></dc:creator>
            <pubDate>Sun, 15 Aug 2021 01:24:11 GMT</pubDate>
            <atom:updated>2021-08-15T17:55:03.105Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building a Simple Port-Scanner with Go</h3><p>These days I wanted to make a new project with go, so I went to the <a href="https://github.com/thinkbreak/programming-challenges">programming challenges</a> page and searched for something, the port scanner caught my attention, so I decided to went for it.</p><h3>Disclaimer</h3><p>What we’re gonna use build can’t be used against servers which you don’t have a permission to run. Read <a href="https://nmap.org/book/legal-issues.html">this</a> to understand more</p><h3>Initial Version</h3><p>So first we’ll define a function called PortScan which will accept a server parameter that will be the server which we’ll scan for it and return a list with the available ports. A port number is a 16-bit unsigned integer, thus ranging from 0 to 65535, but 0 is reserved and can’t be used, so we know the number of ports that we’ve to scan. Also we’ve to think about how we’re gonna check if the port is available, for this we can use the net package, he provides us the Dial function, which we can use to test the connection, but a better one would be the DialTimeout because it gives us the possibility to set a timeout to the connection. So let’s define our PortScan()</p><pre><strong>func</strong> <strong>PortScan</strong>(server <strong>string</strong>) []<strong>int</strong> {</pre><pre>        <strong>var</strong> available []<strong>int</strong></pre><pre>        <strong>for</strong> i := 1; i &lt;= 65535; i++ {<br>                ip := server + &quot;:&quot; + strconv.Itoa(i)</pre><pre>                _, err := net.DialTimeout(&quot;tcp&quot;, ip, time.Duration(300)*time.Millisecond)<br>                <strong>if</strong> err == nil {<br>                    available = append(available, i)<br>                }<br>        }</pre><pre>        <strong>return</strong> available</pre><pre>}</pre><p>For this code to work we have to import the following packages:</p><p>net: Package for the DialTimeout function</p><p>strconv: To convert integers to strings and build our server variable</p><p>time: To create a *time.Second parameter</p><p>os: To get arguments from the command line (we’ll see where ahead)</p><p>fmt: To print results to the command line</p><p>Now for our main function</p><pre><strong>func</strong> <strong>main</strong>() {</pre><pre>    fmt.Println(&quot;Cheking for available ports...&quot;)<br>        ports := PortScan(os.Args[1])</pre><pre>    fmt.Println(&quot;Ports available: &quot; ,ports)</pre><pre>}</pre><p>Now that we have our program, we want to build it, to use you can just run with go run main.go &lt;server&gt; where server is the ip address which you’ll want to check. Let’s use time command to check for the time it takes to run:</p><pre>┌─[nivaldogmelo@yggdrasil] <strong>-</strong> [/port-scanner]<br>└─[$] <strong>time</strong> <strong>go</strong> <strong>run</strong> <strong>port-scanner-no-goroutines</strong>.go <strong>localhost</strong><br><strong>Checking</strong> <strong>for</strong> <strong>available</strong> <strong>ports</strong>...<br><strong>Ports</strong> <strong>available</strong>:  [4000 40031 42987 57621]</pre><pre><strong>real</strong>    20.40s<br><strong>user</strong>    8.74s<br><strong>sys</strong>     12.14s</pre><p>Note that it took a reasonable time, that’s because we check one port at a time, so let’s try to check for multiple ports at the same time</p><h3>Using Goroutines</h3><p>To increase the speed of our test we could check at multiple ports at the same time. For this we can use <em>go routines</em>, which are similar to <em>threads</em> in languages like Java. If you don’t know what a routine is I recommend reading the <a href="https://golangbot.com/learn-golang-series/">Golang Bot</a> tutorial (sections 20–23) to have an idea about what we’re gonna handle. The first thing we’re gonna do is import the sync package to deal with the goroutines. Now we’re gonna do some changes at the structure of the code. First we’re gonna make the available variable a global one, because it will create be manipulated by multiple routines. Second it’s to create a struct to define a job that will be executed</p><pre><strong>type</strong> Job <strong>struct</strong> {<br>        server <strong>string</strong><br>        port   <strong>int</strong><br>}</pre><pre><strong>var</strong> available []<strong>int</strong><br><strong>var</strong> jobs = make(<strong>chan</strong> Job, 10)</pre><p>The jobs variable keeps a buffered channel, which is a channel that will store a buffer of jobs to be executed, we defined the channel to have a length of 10, which means it can hold a maximum of 10 jobs at the same time, any other job will be blocked until some one of the jobs is terminated.</p><p>Now we’re gonna define our createWorkerPool(), which will create our workers to execute the job. Basically it’s here where we define how many concurrent jobs we’ll run at the same time. To initiate a new goroutine we just need to execute our function with a go preceding it. We use the wg.Add(1) to add a new routine to execute our jobs. At the end the wg.Wait() is required to our main routine to wait for the subsequent routines to be completed before moving to the next step. The go worker(&amp;wg) needs to use a pointer so that way it will use the same WaitGroup created by the function, otherwise would create a new one and the tasks would be executed at another goroutines and our original wg group of routines would never be finished</p><pre><strong>func</strong> <strong>createWorkerPool</strong>(noOfWorkers <strong>int</strong>) {<br>        <strong>var</strong> wg sync.WaitGroup<br>        <strong>for</strong> i := 0; i &lt; noOfWorkers; i++ {<br>                wg.Add(1)<br>                <strong>go</strong> worker(&amp;wg)<br>        }<br>        wg.Wait()<br>}</pre><p>Now we need to create a worker() to execute our job.</p><pre><strong>func</strong> <strong>worker</strong>(wg *sync.WaitGroup) {<br>        <strong>for</strong> job := <strong>range</strong> jobs{<br>                ip := job.server + &quot;:&quot; + strconv.Itoa(job.port)</pre><pre>                _, err := net.DialTimeout(&quot;tcp&quot;, ip, time.Duration(300)*time.Millisecond)<br>                <strong>if</strong> err == nil {<br>                        available = append(available, job.port)<br>                }<br>        }<br>        wg.Done()<br>}</pre><p>Now we handle the ip assembly in the worker function, with parameters that we’ll receive from the jobs buffer, composed by variables with the Job struct type, which contains a server and a port. The net.DialTimeout will be executed as in our previous PortScan() and to finish the function we need to pass a wg.Done() , indicating the goroutine that the task is completed.</p><p>As we introduced these changes, we’ll have to change our original PortScan() . Now the function will be called with an additional parameter, a channel which will be written once all the jobs are executed. For each port we’ll build a Job type variable and send it to our jobs list. At the end we’ll close the jobs channel since all jobs have been assigned and no other job will be written to the channel. At the end we pass the true value to the done channel, to indicate we’ve finished the execution of all our goroutines.</p><pre><strong>func</strong> <strong>PortScan</strong>(done <strong>chan</strong> <strong>bool</strong>, server <strong>string</strong>) {<br>        <strong>for</strong> i := 1; i &lt;= 65535; i++ {<br>                job := Job{server, i}<br>                jobs &lt;- job<br>        }<br>        close(jobs)<br>        done &lt;- true<br>}</pre><p>To end our implementation, we make the needed change at our main()</p><pre><strong>func</strong> <strong>main</strong>() {<br>        fmt.Println(&quot;Cheking for available ports...&quot;)<br>        done := make(<strong>chan</strong> <strong>bool</strong>)<br>        <strong>go</strong> PortScan(done, os.Args[1])<br>        noOfWorkers := 10<br>        createWorkerPool(noOfWorkers)<br>        &lt;-done</pre><pre>        fmt.Println(&quot;Ports available: &quot; , available)</pre><pre>}</pre><p>First we create our done channel, then we create a goroutine to run our PortScan getting the parameter that we’ll pass at the command line. Then we set a number of workers and create a worker pool of this size, for the sake of this demo we’ll go with 100 workers. Then we wait for the done channel to return a true value. So we only need to need to print the available ports.</p><p>Ok so we’ve done a few changes on our code, but what have we achieved with this, so let’s use our time command to measure the performance:</p><pre>┌─[nivaldogmelo@yggdrasil] <strong>-</strong> [/port-scanner]<br>└─[$] <strong>time</strong> <strong>go</strong> <strong>run</strong> <strong>port-scanner-goroutines</strong>.go <strong>localhost</strong><br><strong>Checking</strong> <strong>for</strong> <strong>available</strong> <strong>ports</strong>...<br><strong>Ports</strong> <strong>available</strong>:  [4000 40031 42987 57621]</pre><pre><strong>real</strong>    4.37s<br><strong>user</strong>    4.93s<br><strong>sys</strong>     5.21s</pre><p>Now we’ve reached a smaller time</p><h3>Final considerations</h3><p>When hiting a remote server be careful with the number of workers used, because some routers limit the number of concurrent threads, so some ports will be skipped</p><p>And that’s it, I hope you guys enjoyed, if you have any questions you can send me an email or reach me through any of my social media accounts</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6505374e2bc4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Como fazer um Multibranch Pipeline no Jenkins]]></title>
            <link>https://medium.com/@nivaldogmelo/como-fazer-um-multibranch-pipeline-no-jenkins-849b04caafc3?source=rss-306cb82a4497------2</link>
            <guid isPermaLink="false">https://medium.com/p/849b04caafc3</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[github-webhook]]></category>
            <dc:creator><![CDATA[Nivaldo Melo]]></dc:creator>
            <pubDate>Sun, 03 Feb 2019 19:01:45 GMT</pubDate>
            <atom:updated>2019-02-05T09:03:24.100Z</atom:updated>
            <content:encoded><![CDATA[<p>Hoje vim falar para vocês sobre algo que tenho usado nos últimos tempos e tem sido bastante útil no mundo de CI/CD, Multibranch Pipeline. Diferente do Pipeline Job, ele é capaz de trabalhar com diferentes branchs de um projeto no Jenkins. Para exemplificar isso farei um pequeno tutorial subindo uma Multibranch Pipeline apontando um repositório no Jenkins.</p><p>Primeiramente vamos instalar o Jenkins, por motivos de simplicidade vamos usar o docker, então certifique-se de o ter <a href="https://docs.docker.com/install/">instalado</a> e rode o comando</p><pre><em>sudo usermod -aG docker $(whoami)</em></pre><p>Para adicionar o seu usuário ao grupo docker e poder usar o docker sem o sudo. Feito isso vamos ao jenkins.</p><p>Para esse tutorial vamos usar a imagem jenkins lts com alpine linux por ser mais leve. Para iniciar rode o comando</p><pre><em>docker run -d — name=jenkins -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts-alpine</em></pre><p>Vamos explicar esse comando.</p><ul><li><em>-d: </em>executar o container em background</li><li><em>-p:</em> é usado para port-forward, que serve para redirecionar portas , 8080 é onde fica a interface web do jenkins enquanto 50000 é para o remote Java (JIRA) API, que pode ser utilizado para os workers se conectarem ao Jenkins master.</li></ul><p>Você pode também configurar um volume com <em>-v jenkins_home:/var/jenkins_home</em> para persistir dados mesmo com deleção do container.</p><p>Após subir o container você pode acessá-lo em localhost:8080, a tela inicial irá pedir para você buscar a senha inicial de admin, para buscá-la você precisará entrar no container e buscar o arquivo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C67uubF2A_3zxaqE" /></figure><p>Entre no container com <em>docker exec -ti jenkins </em>e para buscar a senha rode</p><pre>cat /var/jenkins_home/secrets/initialAdminPassword</pre><p>Pegue essa senha e coloque no campo necessário, com isso você aparecerá a uma tela onde você pode escolher os plugins que irá instalar, clique em <strong>Select Plugins to Install </strong>e certifique-se de que serão instalados os plugins <strong>Folders,</strong> <strong>Pipeline </strong>e <strong>GitHub Branch Source</strong>. Após a instalação você vai criar seu usuário e então definir a url do seu jenkins, como estamos rodando um docker local então será <a href="http://localhost:8080/">http://localhost:8080/</a> mesmo. Pronto, agora temos nosso jenkins preparado.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LwlJeACMUrnrQVs0" /></figure><p>Vamos agora criar um novo job no jenkins, clique em <strong>New Item &gt; Multibranch Pipeline</strong>, dê um nome e clique em Ok. Agora estaremos na tela de configuração do pipeline</p><p>Na primeira parte podemos definir o nome que será mostrado na interface do Jenkins e uma descrição para o Job. Em seguida temos o campo <strong>Branch Sources</strong>, selecionamos <strong>Github</strong> e aparecerá um campo para preencher. Adicione suas credenciais caso queira puxar dados de um repo privado, logo depois coloque em “owner” o dono do repositório e então no campo repository aparecerá os repositórios disponíveis para você buscar, no meu caso usarei este <a href="https://github.com/nivaldogmelo/multibranch-job.git">repositório</a>, na parte de behavior você pode colocar o que achar interessante, como quais branchs buildar (com regex ou wildcards), em <strong>Build Configuration </strong>deixaremos por Jenkinsfile e o nome do arquivo será Jenkinsfile mesmo.</p><p>Após dar um ok o Jenkins automaticamente começará a escanear o repositório em busca dos Jenkinsfiles. Caso tenha adicionado meu repositório ele achará duas branchs, master e dev com dois Jenkinsfiles</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/774db7c40397000d5ed17be20d272794/href">https://medium.com/media/774db7c40397000d5ed17be20d272794/href</a></iframe><p>Para a master branch e</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fa6f97c2b13df606064929ac853b4a1/href">https://medium.com/media/1fa6f97c2b13df606064929ac853b4a1/href</a></iframe><p>Para a branch dev</p><p>Para diferenciar as branchs, na dev eu coloquei também um pequeno hello world em java</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07d9cd3162bde14e06fb855ef2f31d2d/href">https://medium.com/media/07d9cd3162bde14e06fb855ef2f31d2d/href</a></iframe><p>Após o Jenkins executar os scripts, você terá a interface do job mais ou menos assim</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TTUX_sQiCfjwfR7IDaFNQA.png" /></figure><p>Para escanear o repositório e ver se houve alguma alteração basta clicar em <strong>Scan Repository Now</strong></p><p>Para rodar um job de uma branch específica, sem a necessidade de escanear por alterações no github, basta abrir a página da branch e clicar em <strong>Build Now</strong></p><p>Só para fechar, algo interessante, mas que não farei hoje, é a possibilidade de criar um webhook entre o github e o Jenkins, assim a cada push, pull request ou outros eventos que você definir o Github irá mandar um request no Jenkins, fazendo com que ele inicie o job na branch que recebeu a alteração.</p><p>Para fazer isso você precisará ir no seu repositório (você deve ser dono do repositório para criar o webhook), clicar em em <strong>Settings -&gt; Webhooks -&gt; Add Webhook</strong> colocar a <a href="https://jenkins-url/github-webhook/">https://jenkins-url/github-webhook/</a> onde jenkins-url será a url que você escolheu para o Jenkins na instalação. Note que para o request chegar ao seu Jenkins sua url precisa ser pública, logo localhost não irá funcionar, após isso você poderá selecionar somente os eventos push ou selecionar individualmente quais eventos você quer que sejam mandados.</p><p>E é isso, assim que fazemos um multibranch pipeline no Jenkins. Espero que tenham gostado, podem deixar dúvidas, críticas e sugestões. Até a próxima!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=849b04caafc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>