포시코딩

Integrate Bitbucket & Jenkins 본문

카테고리 없음

Integrate Bitbucket & Jenkins

포시 2024. 6. 8. 18:33
728x90

https://medium.com/@mustafaburakaydiin/integrate-bitbucket-jenkins-58f383f70ead

 

Integrate Bitbucket & Jenkins

The situation we will discuss in this article is the automatic update and recompilation of your project on the server when you push changes…

medium.com

 

Github가 익숙하다면 아래 링크에서 연습 후 하면 이해가 빠를것이다.

https://velog.io/@doyuni/Jenkins-NAVER-Cloud-Platform-Docker로-CICD-무중단-배포-환경-구축하기-1편-khk4w6hrm0

 

Jenkins, NAVER Cloud Platform, Docker로 CI/CD 무중단 배포 환경 구축하기 - 1편

이번 내용은 필자가 프로젝트를 진행하면서 처음으로 DevOps를 맡으면서 꼭 공유 하겠다고 마음 먹고 작성하였다. CI/CD란? CI(Continuous Integration) 지속적인 통합을 의미한다. 이는 개발자를 위한 자

velog.io

 

 

 

 

 

To explain these steps more clearly, I will break them down into 9 sections and demonstrate them step by step.

  1. Creating a Webhook on Bitbucket
  2. Creating Bitbucket password
  3. Creating SSH Key
  4. Jenkins installation with Docker
  5. Jenkins Plugins
  6. Creating Jenkins Global Credentials
  7. Jenkins Configuration
  8. SSH Servers
  9. Creating Jenkins Project
 

1. Creating a Webhook Bitbucket

After creating the repository, when you go to the Repository / Webhooks section, you create a webhook as follows.

Title : You can give any title (exp: jenkins-webhook)

URL : http://JenkinsServerIpAdress:jenkinsPort/bitbucket-hook/

Bitbucket Webhooks
 

2. Creating a Password on Bitbucket

We create a password to access the private repository. To do this, navigate to Personal Bitbucket Settings / App passwords.

Bitbucket Password
 

3. Creating SSH Key

We need to connect to our server where our projects will run via SSH as the root user. If you don’t know how to connect as root, you can follow the steps in this link to complete your configurations.

We are creating SSH keys.

ssh-keygen -t rsa -b 2048

We navigate to the directory where our SSH keys are generated.

cd /root/.ssh

Copy the SSH key we created into the authorized_keys file.

cat id_rsa.pub > authorized_keys

View and save your public key as shown below. We will use it when configuring the server on Jenkins.

cat id_rsa
 

4. Jenkins installation with Docker

Make sure Docker Engine is installed on your server, and then run this command.

docker run -p 8080:8080 -p 50000:50000 --restart=on-failure -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk17

Once Jenkins starts running, you will see a password in the console. Log in with that password and complete the custom installation.

 

5. Jenkins Plugins

To install the required plugins for Bitbucket and server configurations, go to Dashboard/Manage Jenkins/Plugins/Available plugins/ and add the following plugins.

  1. Bitbucket
  2. SSH Server
  3. SSH Plugin
  4. SSH Credentials Plugin
  5. SSH Build Agents Plugin
  6. Publish Over SSH
 

6. Creating Jenkins Global Credentials

Navigate to Dashboard / Manage Jenkins / Credentials / System / Global credentials (unrestricted) and create credentials.

  1. Username : Bitbucket Username
  2. Password: In the second step, enter the password you created on Bitbucket.
Create Credentials
 

7. Jenkins Configuration

Go to Dashboard / Manage Jenkins / System,

Key: In the third step, write the key from the id_rsa you created.

8. SSH Servers ;

Name: ServerName.

Hostname: Server Ip Adress.

Username: SSH connection username (root).

Remote Directory: The file directory where the files in the Bitbucket Repo are copied.

Afterward, click on the Advanced option and go to the Use password authentication, or use a different key section:

Passphrase / Password: Enter the SSH connection password.

 

9. Creating Jenkins Project

First, we are creating a Jenkins project Dashboard / New Item / Freestyle Project

Next, click on the Git option under Source Code Management and fill it out as follows.

Source Code Management

Under the Build Triggers tab, click on the option Build when a change is bushed to Bitbucket and provide the .git extension link of your repository.

Build Triggers

In the Build Stepssection, select the option Send files or execute commands over SSHand complete your configurations.

Name: In step 8, select the name of the SSH server you created.

Source Files: To retrieve all files in the repository, use the ‘**/*’ command.

Exec Command: You can run any Bash script you want.

Attention: Don’t forget to include #!/bin/bash at the beginning to execute a Bash script.

Build Steps

After saving, when you commit and push to the designated branch, your repository will be updated on the server and will run along with the specified Bash command.

728x90