/learn-jenkins-app

[Learning Material] I organized unfamiliar contents of Implementing CI with Jenkins !

Primary LanguageJavaScript

Learn Jenkins App

This project was bootstrapped with Create React App.

How to run Docker Container in Jenkins

This project is node.js. So we need node runtime environment to run javascript. However, Jenkins does not provide default node environment, Therefore we will be using docker container

dashboard - > Jenkins setting -> plugin -> docker pipeline

Then , we are able to use docker container in pippeline

pipeline{
    agent any

    stages{
        stage('w/ docker'){
            agent{
                docker{
                    image 'node:18-alpine'
                }
            }
        }
    }

}

docker will pull the image if it has not been installed.

Workspace synchronization

when using docker, I used agent stage twice and it made my workspace created seperately
To avoid that, we can use reuseNode true.

pipeline {
    agent any

    stages {
        stage('w/o docker') {
            steps {
                sh '''
                    echo "without docker"
                    ls -la
                    touch container-no.txt
                    '''
            }
        }
        
         stage('w/ docker') {
             agent{
                 docker{
                     image 'node:18-alpine'
                     reuseNode true
                 }
             }
            steps {
                sh '''
                    echo "with docker"
                    ls -la   
                    touch container-yes.txt
                '''
            }
        }
        
    }
}

image

Using a git Repository in jenkins

create Jenkinsfile in root directory on workspace

image

Then, Write the pipeline that you want to buid in Jenkinsfile

After that, go to Jenkins , In the configure -> pipeline, simply switch definition pipeline to "pipeline script from scm(Source Code Management)"
Then write as follows

image
image

After completing everything, build Jenkins and it's complete.

If we have changes in Jenkinsfile, push to git again and build again.