Workshop 2: Valid HTML5 Check and surge.sh Deployment (Test and Deploy)
In this exercise, we want to deploy an HTML5 page on the service surge.sh. We also want to check if the HTML5 code is valid. These two operations—checking if the HTML5 is valid (test) and deploying to surge.sh (deploy)—will be automated using Jenkins (CI/CD).
Remember that the repository is https://github.com/josedom24/ic-html5.
As we saw in Example 2, to do the deployment, we need to save the token obtained from surge.sh. Let’s see how to work with credentials in Jenkins.
Create credentials
We can create several types of credentials: user and password, SSH credentials, etc. We will create a Secret text credential to store the surge token.
debian@jenkins:~$ sudo apt install npm
debian@jenkins:~$ sudo npm install -g surge
debian@jenkins:~$ surge token
Login (or create a surge account) by entering your email & password.
email: javierasping@gmail.com
password:
pipeline {
environment {
TOKEN = credentials('SURGE_TOKEN')
}
agent {
docker {
image 'josedom24/debian-npm'
args '-u root:root'
}
}
stages {
stage('Clone') {
steps {
git branch: 'master', url: 'https://github.com/javierasping/taller2_ic-html5.git'
}
}
stage('Install surge') {
steps {
sh 'npm install -g surge'
}
}
stage('Deploy') {
steps {
sh 'surge ./_build/ josedom24.surge.sh --token $TOKEN'
}
}
}
}
We install and configure Ngrok with our token:
debian@jenkins:~$ curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc \
| sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo "deb https://ngrok-agent.s3.amazonaws.com buster main" \
| sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok
debian@jenkins:~$ ngrok config add-authtoken 2d2CfEVHT
Authtoken saved to configuration file: /home/debian/.config/ngrok/ngrok.yml
We indicate in Jenkins that we will use a WebHook:
I launch a correct HTML example and one with errors:
We check that the changes in the repository are received by the WebHook:
On GitHub, we check that it is sending the request to the WebHook: