반응형

 

Jenkins에서 kubernetes pod template을 이용해 dind (docker in docker) 사용방법이다.

 

env에 name: DOCKER_HOST, value: unix:///var/run/docker.sock을 추가하고

securityContext에 privileged 설정을 입력하면된다.

 

아래 스크립트와 같이 작성하면 된다. (insecure은 필요하면 추가하면 됨.)

pipeline {
  agent {
    kubernetes {
      yaml '''
apVersion: v1
knd: Pod
metadata:
  name: inbound-agent
  namespace: jenkins
spec:
  containers:
  - name: dind
    image: docker:28.4.0-dind-alpine3.22
    env:
    - name: DOKCER_HOST
      value: unix:///var/run/docker.sock
    args:
    - --insecure-registry=harbor.wky.kr
    securityContext:
      privileged: true
'''
    }
  }
  stages{
    stage('docker') {
      steps {
        container('dind'){
          script {
            sh 'docker ps'
            sh 'docker build'
          }
        }
      }
    }
  }
}

 

반응형
반응형

Jenknis 에서 Git Checkout 할 경우 파일 용량이 클 때 아래와 같이 기본으로 사용할 경우 10분이 넘어갈 경우 timeout 이 발생한다.

pipeline {
    agent any 
    stages {
        stage('checkout') { 
            steps {
                git branch: 'master', credentialsId: 'credentialsId', url: 'git Repo URL"
            }
        }

    }
}

 

이를 해결하기 위해 스크립트를 사용할 경우 아래와 같이 사용하여 timeout 시간을 늘려준다.

pipeline {
    agent any 
    stages {
        stage('checkout') { 
            steps {
                checkout([
                	$class: "GitSCM",
                	branche: [[name: "master"]],
                	extensions: [
                    	[$class: "CheckoutOption", timeout: 120],
                    	[$class: "CloneOption", timeout: 120]
                    ],
                	gitTool "Default",
                	userRemoteConfigs: [[credentialsId: "credentialsId", url: "git Repo URL"]]
                ])
            }
        }

    }
}

 

반응형
반응형

.

 

Jenkins 에서 Lambda Plugin을 사용한 코드배포 및 함수 실행이다.

 

1. 람다 생성 및 기본적인 플러그인 세팅

1.1) jenkinsTest 람다 함수생성

람다 함수 생성

1.2) Jenkins Lambda Plugin 세팅

젠킨스 플러그인 설치

2. 파이프라인 세팅

pipeline {
    agent any
    
    stages {
        stage('Git CheckOut'){
            steps{
                git branch: 'main', url: 'https://github.com/ / .git'
            }
        }
        stage('Make .zip'){
            steps{
                zip zipFile: 'test.zip'
            }
        }
        stage('lambda deploy'){
            steps{
                 withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'pangyeon',
                    accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]){
                    deployLambda(
                        awsRegion: 'ap-northeast-2',
                        awsAccessKeyId: "${AWS_ACCESS_KEY_ID}",
                        awsSecretKey: "${AWS_SECRET_ACCESS_KEY}",
                        functionName: 'jenkinsTest',
                        artifactLocation: 'test.zip',
                        updateMode: 'code'
                    )
                }
            }
        }
        stage('lambda invoke'){
            steps{
                withAWS(region:'ap-northeast-2', credentials:'pangyeon') {
                    invokeLambda(
                        functionName: 'jenkinsTest'
                    )
                }
            }
        }
    }
    post { 
        always { 
            sh 'rm test.zip'
        }
    }
}

 

3. 실행

 

4. 배포 확인

4.1) 이전 코드

이전 코드

4.2) 배포 후 코드

배포 후 코드

5. 실행 확인

5.1) Jenkins 실행 로그

RequestId : d019e541-92df-4fac-9021-96f150b793c2

Jenkins 실행 로그

5.2) Lambda 로그

RequestId :  d019e541-92df-4fac-9021-96f150b793c2

Lambda 로그

5.1, 5.2의 RequestId가 동일하다는 것을 볼 수 있다.

 

반응형

+ Recent posts