티스토리 뷰

젠킨스 쿠버네티스 플러그인에서 파이프라인 빌드 할 때 git branch를 jenkins에서 파라메터로 넘길 방법을 고민하던중

Jenkinsfile을 git에서 가지고 오다보니 아래와 같이 해주면 git에서 최신버젼으로 클론이 잘 되었습니다.

stage('Clone repository') {
    checkout scm
}

그러나 위 방법을 이용하면 branch name parameter를 넘기는게 안되어서 브랜치를 바꿔서 배포하려면 빌드 할 때 바꿔 주어야 했습니다.

그래서 BRANCH라는 parameter를 넘기려면 git정보를 빌드할 때 만들어 주어야겠다고 생각했고 방법을 찾았습니다.

def label = "aipcommon-${UUID.randomUUID().toString()}"
def nexusHost = "hello.world.com"
podTemplate(label: label, 
  serviceAccount: "jenkins",
  containers: [
      containerTemplate(
      name: 'jnlp',
      image: nexusHost+':5000/inbound-agent:4.3-4',
      args: '${computer.jnlpmac} ${computer.name}'
    ),
      containerTemplate(
      name: 'python37',
      image: nexusHost+":5000/python:3.7.9",
      command: 'cat',
      ttyEnabled: true
    )
      ])
 {
    node(label) {
        print("BRANCH:$BRANCH")
        print("label:" + label)
        stage('Clone repository') {
            print('BRANCH:$BRANCH')
            checkout([$class: 'GitSCM',
                    branches: [[name: '*/dev']],
                    userRemoteConfigs: [
                        [url: 'http://git.com/imagename.git',
                        credentialsId: '1234-5678']
                    ],
                ])
        }
    }
 }

위 code에서 checkout() 부분을 보시면 parameter를 넘길 수 있습니다. credential도 등록 해두었다면 id로 불러오는 것이 가능합니다.

파라메터 이용은 다음과 같이 할 수 있습니다. print("BRANCH:$BRANCH")

end.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함