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 : [링크]
★☆☆☆☆
반응형
댓글