사용자 도구

사이트 도구


ci:jenkins:pipeline

문서의 이전 판입니다!


Jenkins Pipeline

기본 환경변수

  • env.JOB_NAME
  • env.BUILD_NUMBER
  • env.BUILD_URL

Build Parameter

Notification

Archive Artifact

post {
    always {
        archiveArtifacts artifacts: 'build/libs/**/*.jar', fingerprint: true
        junit 'build/reports/**/*.xml'
    }
}

변수 및 Script in Declarative

pipeline {
    agent any
    environment {
        MY_ENV = "${env.BRANCH_NAME}"
    }
    // 아래에서 MY_ENV 변수로 사용
}
  • Scripting을 하려면 steps에서 script 블록을 둔다.
steps {
    echo 'Building Container..'
 
    script {
        if (ENVIRONMENT_NAME == 'development') {
            ENV_NAME = 'Development'
        } else if (ENVIRONMENT_NAME == 'release') {
            ENV_NAME = 'Production'
        }
    }
    echo 'Building Branch: ' + env.BRANCH_NAME
    echo 'Build Number: ' + env.BUILD_NUMBER
    echo 'Building Environment: ' + ENV_NAME
 
    echo "Running your service with environemnt ${ENV_NAME} now"
}

강제 상태변경

  • 상태를 SUCCESS, UNSTABLE, FAILURE로 변경가능하다.
  • error “메시지” : 상태를 FAILURE로 변경하면서 메시지 출력

혹은 직접 지정

currentBuild.result = 'UNSTABLE' // SUCCESS, UNSTABLE, FAILURE

Git Branch Parameter

  • Git Branch 를 Job Parameter로 지정하고자 한다면, Lightweight checkout을 꺼야 한다.
  • GIT_BRANCH가 Job 파라미터 이름
stage('Git Checkout') {
    steps {
        git poll: true,
        changelog: true,
        url: 'git@github.com:....git',
        branch: params.GIT_BRANCH
        credentialsId: '...'
    }
}

JUnit 테스트 결과 메일/Slack 발송

  • 호출하는 메소드가 금지돼 있어서 whitelist 에 추가 필요해 보임. Build 로그 메시지를 잘 보면, whitelist에 추가 시킬수 있는 admin 페이지로의(http://jenkinshost/scriptApproval/) 링크가 출력됨. 이것을 클릭하고서 추가한다.
  • 그 뒤에 계속해서 메소드 하나하나마다 추가하라고 나오므로 $JENKINS_HOME/scriptApproval.xml을 다음과 같이 편집하고 Jenkins를 재시작한다.
    <?xml version='1.0' encoding='UTF-8'?>
    <scriptApproval plugin="script-security@1.23">
    <approvedScriptHashes>
    </approvedScriptHashes>
    <approvedSignatures>
    <string>method hudson.model.Actionable getAction java.lang.Class</string>
    <string>method hudson.model.Cause getShortDescription</string>
    <string>method hudson.model.Run getCauses</string>
    <string>method hudson.tasks.test.AbstractTestResultAction getFailCount</string>
    <string>method hudson.tasks.test.AbstractTestResultAction getFailureDiffString</string>
    <string>method hudson.tasks.test.AbstractTestResultAction getSkipCount</string>
    <string>method hudson.tasks.test.AbstractTestResultAction getTotalCount</string>
    <string>method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild</string>
    </approvedSignatures>
    <aclApprovedSignatures/>
    <approvedClasspathEntries/>
    <pendingScripts/>
    <pendingSignatures/>
    <pendingClasspathEntries/>
    </scriptApproval>

참조

ci/jenkins/pipeline.1543387476.txt.gz · 마지막으로 수정됨: 2018/11/28 15:44 저자 kwon37xi