将jenkins变量传给python脚本
- python脚本
import os
def get_jenkins_env(env_name):
return os.environ[env_name]
if __name__ == '__main__':
print('---------------------')
print('jenkins_environment',get_jenkins_env('SERVICES'))
print('---------------------')
- bat脚本
@echo off
path\python.exe path/get_jenkins_env.py
pause
- pipeline配置
pipeline {
agent any
environment {
SERVICES = "myservices"
}
stages {
stage('执行bat文件'){
steps {
bat '''path\\batname.bat'''
}
}
}
}
- 结果