Monday, April 23, 2018

How to upgrade Git on Windows

1. Go to https://git-scm.com/download/win and download the .exe program



2. Execute it and follow the wizard (you do not need to uninstall your previous version of git to upgraded it to the latest)
3. That's it!





Wednesday, April 18, 2018

How can I upgrade Node.js and npm on Windows?

Cómo actualizar Node.js y NPM en Windows?

The most easy way to upgrade your Node.js and NPM on Windows, is go to https://nodejs.org/es/download/current/ and download the Windows Installer, run the .msi, follow the steps but make sure the path you enter is the same as the old one. That's it!

La manera más sencilla de actualizar Node.js y NPM en tu máquina Windows, es descargando el MSI más reciente, que lo encuentras en este link https://nodejs.org/es/download/current/ Sigue el wizard, pero asegurate de ingresar la misma ruta donde se encuentra tu version actual. Probablemente sea: C:\Program Files\nodejs

Let's see...



Wednesday, April 11, 2018

How to post a file version as an artifact in Jenkins

If you are using a Jenkinsfile and want to save a txt file with the build number, you just to use the $BUILD_NUMBER environment variable:

  sh 'echo "build $BUILD_NUMBER" > version.txt'

Then, in post section - always, you can post your version.txt file:

  post {
        always {
            archiveArtifacts artifacts: 'build/ , version.txt'
        }
    }

Here in the example, I am posting two files separated by commas. 

Jenkinsfile


Output


Monday, April 9, 2018

Eslint - FatalProcessOutOfMemory


FatalProcessOutOfMemory
FATAL ERROR CALL AND RETRY LAST
allocation failed - Javascript heap out of memory

I am getting this error after run *yarn run lint* for my create-react-app project.


This is due to the gigantic bundle.

I have something like this:

"lint": "eslint --ext .jsx --ext .js ."

Fix: change that line for this one:

"lint": "./node_modules/.bin/eslint . --ext ./src/*.js --ext ./src/*.jsx"

or you can use this ones:

"lint": "eslint -- --max_old_space_size=4096 --ext .jsx --ext .js ."

"lint": "./node_modules/.bin/eslint --ext .jsx --ext .js ./src"

1024 #increase to 1gb
2048 #increase to 2gb
3072 #increase to 3gb
4096 #increase to 4gb
5120 #increase to 5gb
6144 #increase to 6gb
7168 #increase to 7gb
8192 #increase to 8gb

That worked for me. Just make sure to enter your folder name, the mine is *src*

Friday, April 6, 2018

How to get started with Jenkins and GitLab on Windows

How to get started with Jenkins and GitLab on Windows

If you are really new in this, like me before, I think this guide could help you.
I assume if you are looking for Jenkins, you already know what is Continuous Integration, Continuous Delivery and Continuous Deployment.

But if you don't know yet, don't worry. Here are the definitions:

Continuous Integration. The practice of merging the development work with the main branch constantly so that the code has been tested as often as possible to catch issues early.

The ideal task size is not bigger than a day's work. This way a developer will naturally have at least one integration per day.

Continuous Delivery. Continuous delivery of code to an environment once the code is ready to ship. This could be staging or production. The idea is the product is delivered to a user base, which can be QA's or customers for review and inspection.

Unit test during the Continuous Integration phase can not catch all the bugs and business logic, particularly design issues that is why we need QA, or staging environment for testing.

Continuous Deployment: The deployment or release of code as soon as it's ready. Continuous Deployment requires Continuous Integration and Continuous Delivery otherwise the code quality won't be guarantee in a release.



So, let's move on to the next point.
What is Jenkins? What relationship does Jenkins with the concepts explained lines above?

Jenkins is a Continuous Integration server. Can be used as a simple CI server or turned into the continuous delivery hub for any project. Jenkins helps to automate the non-human part of the software development process, with continuous integration and facilitating technical aspects of continuous delivery.

Enough with the theory. Let's move on to practice.

1. Install Jenkins on your machine. (as a service)
Use the official link: https://jenkins.io/download/
Choose LTS, and Download for Windows.

2. Install the default plugins (includes Git Plugin). Also, install the GitLab Plugin

3. Create a SSH Key pair in GitLab. If you already have one, skip this step. If not yet, use the Generate a new ssh key pair guide from GitLab (User Settings > SSH Keys) This put the keys in C:\Users\MY_USER\.ssh\ (id_rsa for the private key and id_rsa.pub for the public key). You must add the public key as a deploy key to your GitLab project and then add the private key as a Jenkins Credential. This is the next step.

4. Create a credential in Jenkins.
Credentials > System > Add Credentials

Kind: SSH Username with private key
Scope: Global (Jenkins, nodes, items, all child items, etc)
Username: (whatever you want to. Suggest: git)
Private Key: From a file on Jenkins master
File: c:\User\YOUR-USER\ssh\id_rsa
Description: (It is optional)

With this, we are allowing Jenkins to connect to the git host over ssh.

5. Now, we need to setup API Access for Jenkins to get metadata from GitLab.

In GitLab, User Settings > Access Tokens > Add a personal access token.
Copy and save the token because you won't be accessible again.

6. Go Jenkins.
Credentials > System > Add Credentials

Kind: GitLab API token
Scope: Global (Jenkins, ndoes, items, all child items, etc)
API token: (paste here the token)
ID: whatever you want to.
Description: It is optional.

Once the API Access has been setup, we can configure the connection between Jenkins and GitLab. This happens in the Manage Jenkins -> Configure System menu.

In Gitlab section:
Connection name: enter a name.
Gitlab host URL: enter your host.
Credentials: choose the one you just have created
Test Connection, if everything is good, it will show you a Success message.

Now that our connection between Jenkins and GitLab is setup, we need to create a job. You can choose between freestyle jobs or pipeline.

In this guide, we will use a Multibranch Pipeline. (in my case, it works for me because I use develope, master and stable as branches)

In Jenkins, go
New Item > Enter an item name, then select Multibranch Pipeline. Click OK.

Branch Sources section.
Git
Project Repository: copy and paste the URL from GitLab (SSH)
Credentials: Choose the first one we have created.
Click Save.

It is importart your project has the Jenkinsfile in the root. Configure the Jenkinsfile is another topic. But, just for testing, you can have this:



(make sure to change the yarn comand if your project is not using yarn, it could be npm)

The last step is testing.

Go Jenkins, click the job we have created, then click the branch, click Build with Parameters, click Build and wait for building... you can have two output: failure or success.

That's it!


Wednesday, April 4, 2018

How to create a jenkins user

Just browse: Manage Jenkins > Manage Users > Create User

But if you cannot see this path, you must enable:

Manage Jenkins > Configure Global Security > Enable security and Jenkin's own user database should be checked.

That's it!