Programmer:)
[Jenkins] Pipeline Script (환경변수, input, 병렬작업) 본문
반응형
#Pipeline 으로 Job을 생성시 유니티 경로 or 저장할 폴더 경로 등 계속적으로 복붙해야하는 것들과
선택적으로 stage 실행을 하고싶었다.
#기본 Pipeline Script 뼈대
#작업할 stage 추가
#Pipeline Syntax 클릭 후 스크립트 생성 후 추가
(선행작업) gitlab 연동
pipeline {
agent any
stages {
stage('Pull gitlab project') {
steps {
git credentialsId: '******', url: 'git@git.*******.git'
echo 'Pull gitlab project Success'
}
}
stage('Build project') {
steps {
echo 'Hello World'
}
}
stage('SSH upload') {
steps {
echo 'Hello World'
}
}
}
}
#Build Stage 스크립트 작성
(참고)
pipeline {
agent any
stages {
stage('Pull gitlab project') {
steps {
git credentialsId: '******', url: 'git@git.*******.git'
echo 'Pull gitlab project Success'
}
}
stage('Build project') {
steps {
script{
echo "build project 32"
sh (script : """
"/Applications/Unity/Hub/Editor/2019.4.3f1/Unity.app/Contents/MacOS/Unity" -quit -batchmode -projectPath "/Users/apple/.jenkins/workspace/hitest/Application" -executeMethod ProjectBuild.BuildStartTest -buildTarget "StandaloneWindows" -ConnectServer "dev" -Company "hitest" -at 32
""")
}
}
}
stage('SSH upload') {
steps {
echo 'Hello World'
}
}
}
}
#여기서 저 경로들을 좀 더 보기쉽게 환경변수로 빼기
pipeline {
agent any
environment{
UNITY_PATH = "/Applications/Unity/Hub/Editor/2019.4.3f1/Unity.app/Contents/MacOS/Unity"
PROJECT_PATH = "/Users/apple/.jenkins/workspace/hitest/Application"
COMPANY_NAME = "hitest"
BUILD_TARGET = "StandaloneWindows"
CONNECTSERVER = "dev"
}
stages {
stage('Pull gitlab project') {
steps {
git credentialsId: '******', url: 'git@git.*******.git'
echo 'Pull gitlab project Success'
}
}
stage('Build project') {
steps {
script{
echo "build project 32"
sh (script : """
${env.UNITY_PATH} -quit -batchmode -projectPath ${env.PROJECT_PATH} -executeMethod ProjectBuild.BuildStartTest -buildTarget ${env.BUILD_TARGET} -ConnectServer ${env.CONNECTSERVER} -Company ${env.COMPANY_NAME} -at 32
""")
}
}
}
stage('SSH upload') {
steps {
echo 'Hello World'
}
}
}
}
#SSH upload Stage 추가
(참고)
pipeline {
agent any
environment{
UNITY_PATH = "/Applications/Unity/Hub/Editor/2019.4.3f1/Unity.app/Contents/MacOS/Unity"
PROJECT_PATH = "/Users/apple/.jenkins/workspace/hitest/Application"
COMPANY_NAME = "hitest"
BUILD_TARGET = "StandaloneWindows"
CONNECTSERVER = "dev"
}
stages {
stage('Pull gitlab project') {
steps {
git credentialsId: '******', url: 'git@git.*******.git'
echo 'Pull gitlab project Success'
}
}
stage('Build project') {
steps {
script{
echo "build project 32"
sh (script : """
${env.UNITY_PATH} -quit -batchmode -projectPath ${env.PROJECT_PATH} -executeMethod ProjectBuild.BuildStartTest -buildTarget ${env.BUILD_TARGET} -ConnectServer ${env.CONNECTSERVER} -Company ${env.COMPANY_NAME} -at 32
""")
}
}
}
stage('SSH upload') {
steps {
script{
sshPublisher(publishers: [sshPublisherDesc(configName: 'hitest', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false,
makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'Windows/dev/Client', remoteDirectorySDF: false,
removePrefix: 'Application/32bit', sourceFiles: 'Application/32bit/**')],
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
}
}
}
#SSH upload 환경변수에 따라 실행하도록 if문으로 빼기
pipeline {
agent any
environment{
SSH_UPLOAD = "true"
UNITY_PATH = "/Applications/Unity/Hub/Editor/2019.4.3f1/Unity.app/Contents/MacOS/Unity"
PROJECT_PATH = "/Users/apple/.jenkins/workspace/hitest/Application"
COMPANY_NAME = "hitest"
BUILD_TARGET = "StandaloneWindows"
CONNECTSERVER = "dev"
}
stages {
stage('Pull gitlab project') {
steps {
git credentialsId: '******', url: 'git@git.*******.git'
echo 'Pull gitlab project Success'
}
}
stage('Build project') {
steps {
script{
echo "build project 32"
sh (script : """
${env.UNITY_PATH} -quit -batchmode -projectPath ${env.PROJECT_PATH} -executeMethod ProjectBuild.BuildStartTest -buildTarget ${env.BUILD_TARGET} -ConnectServer ${env.CONNECTSERVER} -Company ${env.COMPANY_NAME} -at 32
""")
}
}
}
stage('SSH upload') {
steps {
script{
if("${env.SSH_UPLOAD}" == "true"){
sshPublisher(publishers: [sshPublisherDesc(configName: 'hitest', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false,
makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'Windows/dev/Client', remoteDirectorySDF: false,
removePrefix: 'Application/32bit', sourceFiles: 'Application/32bit/**')],
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
else{
echo "DO NOT UPLOAD"
}
}
}
}
}
}
#병렬 작업 추가 Parallel 부분
pipeline {
agent any
environment{
SSH_UPLOAD = "true"
UNITY_PATH = "/Applications/Unity/Hub/Editor/2019.4.3f1/Unity.app/Contents/MacOS/Unity"
PROJECT_PATH = "/Users/apple/.jenkins/workspace/hitest/Application"
COMPANY_NAME = "hitest"
BUILD_TARGET = "StandaloneWindows"
CONNECTSERVER = "dev"
}
stages {
stage('Pull gitlab project') {
steps {
git credentialsId: '******', url: 'git@git.*******.git'
echo 'Pull gitlab project Success'
}
}
stage('Build project') {
steps {
script{
echo "build project 32"
sh (script : """
${env.UNITY_PATH} -quit -batchmode -projectPath ${env.PROJECT_PATH} -executeMethod ProjectBuild.BuildStartTest -buildTarget ${env.BUILD_TARGET} -ConnectServer ${env.CONNECTSERVER} -Company ${env.COMPANY_NAME} -at 32
""")
}
}
}
stage('SSH') {
parallel{
stage('SSH Send 32bit') {
steps {
script{
if("${env.SSH_UPLOAD}" == "true"){
sshPublisher(publishers: [sshPublisherDesc(configName: 'hitest', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false,
makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'Windows/dev/Client', remoteDirectorySDF: false,
removePrefix: 'Application/32bit', sourceFiles: 'Application/32bit/**')],
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
else{
echo "DO NOT UPLOAD"
}
}
}
}
stage('SSH Send 64bit') {
steps {
script{
if("${env.SSH_UPLOAD}" == "true"){
sshPublisher(publishers: [sshPublisherDesc(configName: 'hitest', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false,
makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'Windows/dev/Client', remoteDirectorySDF: false,
removePrefix: 'Application/64bit', sourceFiles: 'Application/64bit/**')],
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
else{
echo "DO NOT UPLOAD"
}
}
}
}
}
}
}
}
#환경변수 if문 input message로 수정
SSH 병렬작업 전 작업진행 여부 message창 팝업
Yes -> 작업진행
abort -> 빌드까지만 진행 SSH 작업 중단
pipeline {
agent any
environment{
SSH_UPLOAD = "true"
UNITY_PATH = "/Applications/Unity/Hub/Editor/2019.4.3f1/Unity.app/Contents/MacOS/Unity"
PROJECT_PATH = "/Users/apple/.jenkins/workspace/hitest/Application"
COMPANY_NAME = "hitest"
BUILD_TARGET = "StandaloneWindows"
CONNECTSERVER = "dev"
}
stages {
stage('Pull gitlab project') {
steps {
git credentialsId: '******', url: 'git@git.*******.git'
echo 'Pull gitlab project Success'
}
}
stage('Build project') {
steps {
script{
echo "build project 32"
sh (script : """
${env.UNITY_PATH} -quit -batchmode -projectPath ${env.PROJECT_PATH} -executeMethod ProjectBuild.BuildStartTest -buildTarget ${env.BUILD_TARGET} -ConnectServer ${env.CONNECTSERVER} -Company ${env.COMPANY_NAME} -at 32
""")
}
}
}
stage('SSH') {
input{
message "Continue SSH uploading?"
ok "Yes"
parameters{
string(name: 'ANSWER', defaultValue: 'Yes', description: '')
}
}
parallel{
stage('SSH Send 32bit') {
steps {
script{
if("${ANSWER}" == "Yes"){
sshPublisher(publishers: [sshPublisherDesc(configName: 'hitest', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false,
makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'Windows/dev/Client', remoteDirectorySDF: false,
removePrefix: 'Application/32bit', sourceFiles: 'Application/32bit/**')],
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
else{
echo "DO NOT UPLOAD"
}
}
}
}
stage('SSH Send 64bit') {
steps {
script{
if("${ANSWER}" == "Yes"){
sshPublisher(publishers: [sshPublisherDesc(configName: 'hitest', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: '', execTimeout: 120000, flatten: false,
makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: 'Windows/dev/Client', remoteDirectorySDF: false,
removePrefix: 'Application/64bit', sourceFiles: 'Application/64bit/**')],
usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
}
else{
echo "DO NOT UPLOAD"
}
}
}
}
}
}
}
}
반응형
'DEV > Jenkins' 카테고리의 다른 글
[Jenkins]Email Notification (부들부들 starttls.... ) (0) | 2022.05.13 |
---|---|
[Jenkins] Unity - IOS Build , Xcode 아카이브 방법 (0) | 2022.04.29 |
[Jenkins] SSH연동 (freestyle, Pipeline) (0) | 2022.04.25 |
[Jenkins-Pipeline] Pipeline 구성 (commandline 인자 값 받아오기) (0) | 2022.04.21 |
[Jenkins-Pipeline] Jenkins(Mac...Windows..) - GitLab 연동 (0) | 2022.04.21 |
Comments