Jenkins 파이프 라인의 조건부 단계 / 단계
특정 브랜치를 빌드하는 경우에만 빌드 단계 / 단계를 어떻게 실행합니까?
예를 들어 분기가 호출 된 경우에만 배포 단계를 실행하고 deployment
나머지는 모두 그대로 둡니다.
다음은 선언적 파이프 라인 구문에서 동일한 작업을 수행하는 몇 가지 예입니다.
stage('master-branch-stuff'){
agent any
when{
branch 'master'
}
steps {
echo 'run this stage - ony if the branch = master branch'
}
}
stage('feature-branch-stuff') {
agent label:'test-node'
when { branch "feature/*" }
steps {
echo 'run this stage - only if the branch name started with feature/'
}
}
stage('expression-branch') {
agent label:'some-node'
when {
expression {
return env.BRANCH_NAME != 'master';
}
}
steps {
echo 'run this stage - when branch is not equal to master'
}
}
stage('env-specific-stuff') {
agent label:'test-node'
when {
environment name: 'NAME', value: 'this'
}
steps {
echo 'run this stage - only if the env name and value matches'
}
}
더 효과적인 방법-https: //issues.jenkins-ci.org/browse/JENKINS-41187
또한보세요-https: //jenkins.io/doc/book/pipeline/syntax/#when
새로운 WHEN 조항
REF 업데이트 : https://jenkins.io/blog/2018/04/09/whats-in-declarative
같음-두 값 (문자열, 변수, 숫자, 부울)을 비교하고 같으면 true를 반환합니다. 나는 솔직히 우리가 이것을 더 일찍 추가하는 것을 어떻게 놓쳤는 지 잘 모르겠습니다! not {equals ...} 조합을 사용하여 "not equals"비교를 수행 할 수도 있습니다.
changeRequest-가장 간단한 형식으로이 파이프 라인이 GitHub 풀 요청과 같은 변경 요청을 빌드하는 경우 true를 반환합니다. 또한 "마스터 브랜치에 대한 변경 요청입니까?"라고 질문 할 수 있도록 변경 요청에 대해 더 자세한 검사를 수행 할 수도 있습니다. 그리고 훨씬 더.
buildingTag-파이프 라인이 브랜치 나 특정 커밋 참조가 아닌 SCM의 태그에 대해 실행 중인지 확인하는 간단한 조건입니다.
tag-태그 이름 자체를 확인할 수있는 buildingTag에 해당하는 더 자세한 내용입니다.
Just use if
and env.BRANCH_NAME
, example:
if (env.BRANCH_NAME == "deployment") {
... do some build ...
} else {
... do something else ...
}
참고URL : https://stackoverflow.com/questions/37690920/conditional-step-stage-in-jenkins-pipeline
'Nice programing' 카테고리의 다른 글
WHERE 절에서 SELECT 문을 사용하여 SQL DELETE 문을 작성하는 방법은 무엇입니까? (0) | 2020.11.26 |
---|---|
Jackson ObjectMapper-객체 속성의 직렬화 순서 지정 (0) | 2020.11.26 |
Python 확장-swig 또는 Cython이 아닌 swig로 (0) | 2020.11.26 |
C #에서 다차원 키가있는 해시 테이블 (0) | 2020.11.26 |
포함 된 이미지가 포함 된 Multipart HTML 이메일 보내기 (0) | 2020.11.26 |