본문 바로가기
개발/게임) 개발관련

Jenkins Groovy) OS 구분 코드

by 테샤르 2023. 3. 18.

Jenkins Groovy) OS 구분 코드

Jenkins Groovy 에서  OS 구분 코드는 다음과 같다. 

pipeline {
  agent any
  
  stages {
    stage('Check OS') {
      steps {
        script {
          if (isUnix()) {
            echo "Running on a Unix-based OS"
          } else {
            echo "Running on a Windows-based OS"
          }
        }
      }
    }
  }
}

 

반응형

다른 형식도 존재하긴하지만 보안상으로 문제가 있다고 나온다.

System.getProperty를 제외항목으로 추가하게되면  외부에서도 해당 값을 읽을수 있기 때문이다. (비추)

def CheckOS(){
    String osname = System.getProperty('os.name');
    if (osname.startsWith('Windows'))
        return 'windows';
    else if (osname.startsWith('Mac'))
        return 'macosx';
    else if (osname.contains('nux'))
        return 'linux';
    else
        throw new Exception("Unsupported os: ${osname}");
}

 

Jenkins isUnix : [링크]

 

Pipeline: Basic Steps

catchError: Catch error and set build result to failure If the body throws an exception, mark the build as a failure, but nonetheless continue to execute the Pipeline from the statement following the catchError step. The behavior of the step when an except

www.jenkins.io

 

★☆☆☆☆

 

반응형

댓글