Jenkins设置编码utf8在bat脚本中不起作用

8qgya5xd  于 12个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(157)

我尝试将jenkins编码设置为utf-8,但在某些情况下似乎不起作用,这是我的管道文件:

def Notify(environment, type , content ){
    echo environment
    bat script: 'node D:\\JenkinsNotify\\notify.js '+ environment+'  '+ type +' '+ content+' '+ env.WORKSPACE
    
  
}
pipeline {
   agent {label 'master'}
   
    environment {
       
        LC_ALL = 'en_US.UTF-8'
        LANG    = 'en_US.UTF-8'
        LANGUAGE = 'en_US.UTF-8'
  
    }
    stages {
        
       stage('消息通知'){
            steps {
                echo 'notify'
            }
            post {
            
                success {
                    script{
                        Notify("开发测试环境",'text',"构建成功")
                    }
                }
                failure {
                  script{
                        Notify("开发测试环境",'text',"构建失败")
                    }
                }
            }
       }
        
    }
    
}

输出不是预期的,编码不正确:

D:\Jenkins\workspace\TestDemo>node D:\JenkinsNotify\notify.js 开发测试环�? text 构建成功 D:\Jenkins\workspace\TestDemo 
[
  'C:\\Program Files\\nodejs\\node.exe',
  'D:\\JenkinsNotify\\notify.js',
  '寮€鍙戞祴璇曠幆澧?',
  'text',
  '鏋勫缓鎴愬姛',
  'D:\\Jenkins\\workspace\\TestDemo'
]
测试中文能不能正常输入

notify.js文件:

const arr = process.argv;

console.log(arr);
console.log('测试中文能不能正常输入');

我已经在jenkins.xml中设置了jenkins的启动参数-Dfile.encoding=utf-8,并在Jenkins系统配置中设置了LANG=zh_CN.UTF-8LC_ALL=zh_CN.UTF-8,但它们不工作。

我不知道如何解决这个问题,花了我好几个小时还是没有答案
我试过这样做:

def NotifySuccess(environment){
    bat encoding:'UTF-8', script: 'node D:\\JenkinsNotify\\notify2.js 中文测试为什么不行 '+ environment+ env.WORKSPACE
    //bat script: 'node D:\\JenkinsNotify\\notify.js PDM_Backend_DevTest text true '+ env.WORKSPACE
}

但它仍然不起作用:

node D:\JenkinsNotify\notify2.js 中文测试为什么不�?测试中文输入是否可行D:\Jenkins\workspace\PDM_Backend_DevTest@2

环境

  • Jenkins2.414.1
  • Windows Server 2022 21H2
bakd9h0s

bakd9h0s1#

bat步骤中缺少encoding参数。尝试添加encoding: 'UTF-8'

相关问题