Jenkins Install

킹콩(King Kong)·2024년 12월 12일

Jenkins install

Jenkins 다운로드 (LTS version)

https://jenkins.io/download
Generic Java Package(.war) download

OS 환경변수

export JENKINS_HOME=/data/nexus/jenkins/webapps

JDK11 이상 필요

nohup /jdk-11.0.20/bin/java -jar jenkins.war --httpPort=9090 --profix=/jenkins &

Proxy 연동

/jenkins로 호출시 뒷단 Jenkins 서비스로 포워딩
jenkins.war 살릴때 ContextPath 추가

java -jar jenkins.war --prefix=/jsnkins

Init Password

cat /data/nexus/jenkins/webapps/secrets/initialAdminPassword


Jenkins Plug-in Install

1. HTTPS 오류가 발생하면 plug-in을 먼저 설치한다.

https://updates.jenkins-ci.org/download/plugins/skip-certificate-check

  • 다운받아서ㅊ 에 복사후 재실행
  • 이렇게 받은 파일을 확자자를 .jpi -> .hpi로 변경해서 내부에 반영
  • $JENKINS_HOME/plugins에 복사후 재실행

2.Jenkins 설치 후 환경설정

Jenkins 관리 > Tools > JDK installations
Jenkins 관리 > Tools > Maven installations 또는 Jenkins 관리에서 Maven Plugin 추가
Git설치확인 : Linux의 경우 Git이 설치되어 있어야 함

3.Project별 Role 관리

Jenkins관리 > Security > Authorization : Project-based Matrix Authorization Strategy 선택
Plug-ins에 Role관리 Plugin 추가해야 함
:Matrix Authorization Strategy
:Role-based Authorization Strategy

Build item > 구성 > "Enable project-based security"선택
"Do not inherit permission grants from other ACLs" 선택


Jenkins Pipeline sample

pipleline {
    agent any
    
    tools {
        maven 'maven399'
    }
    
    stages {
        stage('Git Pull') {
            steps {
                echo '======== Git_Pull ========='
                git branch: 'main', credentialsId: 'gitadmin'
                url: 'https://gitea.test.com/test/test.git'
            }
        }
        stage('Build') {
            steps {
                echo '=========== Maven_Build =========='
                sh '''  
                    mvn clean package -DskipTests
                    ls -l
                '''
            }
        }
        stage('Docker Deploy') {
            steps {
                echo '=========== Docker_Deploy ========='
                sh '''
                    docker build -t test-pjt:1.0 .
                    docker tag test-pjt:1.0 registry.test.com/test/test-pjt:1.0
                    docker push registry.test.com/test/test-pjt:1.0
                '''
            }
        }
    }
}

Credential 추가

  • Jenkins관리 > Credentials > System > Globalcredentails (unrestricted)클릭
    • Add Credentials 클릭

      Kind : Username with password
      : Scope , Username, Password, ID(pipeline에서 사용됨) 입력

profile
IT를 쉽게 이해해 보아요~😄

0개의 댓글