Jenkins-Playground
A playground to illustrate the use of Jenkins in CI/CD
To Create & Run the Docker Container
- Create the
package.json
file. - Run
npm install
to generatepackage-lock.json
file. - Create a
server.js
file that defines the web app using the Express.js framework. - Build the image:
docker build . -t docker_web
- Run the image:
docker run -p 8080:8080 -d docker_web
- Get the container ID using the
docker ps
command. - Print the output:
docker logs <container id>
- Enter the Container:
docker exec -it <container id> /bin/bash
- Try testing from outside:
curl -i localhost:8080
To Run Jenkins Inside a New Container
- Run:
docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
- Get the password:
docker ps
->ddocker logs <container id>
-> get the password. - Go to
localhost:8080
. - Choose recommended packages.
- Create a profile with a username and password.
- Start using jenkins!
Connect To a Private Repository Using SSH
- Go to ssh directory:
cd ~/.ssh
- Generate a key:
ssh-keygen -o -t rsa
- When you type
ls
you should find: id_rsa and id_rsa.pub. - Show and copy the contents of the public key:
cat id_rsa.pub
- Go to the repo on github.
- Open settings -> Deploy Keys.
- Add the key and give it a name.
- Open Jenkins -> Manage Jenkins -> Manage Credentials.
- Click global -> Add Credentials.
- Fill: Kind = SSH, ID = any name, Description = any, Username = doesn't matter.
- Private Key -> Enter Key -> Add the whole name (Even the start and the end comments).
- Start a new pipeline.
- Source = (from Github repo -> Code -> SSH).
- Build the Repo!
To Use Docker in Jenkins:
- Install the following plugins:
- Use
agent { dockerfile true }
in the Jenkinsfile.