出现异常错误:无此属性:类的GIT_PASSWORD:groovy.lang.Binding

6mzjoqzu  于 2022-11-01  发布在  Git
关注(0)|答案(1)|浏览(221)

我已经检查了所有关于同一个错误的主题,尝试了一切,但我无法找到任何东西来帮助我解决我的问题。
我的代码构建一个Docker容器,启动一个flask应用程序并运行一个python脚本,运行测试,然后合并Master。代码如下:

pipeline {
agent any

stages {

   stage('Master merging'){

      steps{
         script{
         passwordVariable = 'password'
         usernameVariable = 'unsername'
            // Variables for input
         if(env.BRANCH_NAME == 'features'||env.BRANCH_NAME == 'main'){
         sh 'git checkout origin/features'
         sh 'git pull'
         sh 'git remote update'
         sh 'git fetch'
         sh 'git checkout origin/main'
         sh 'git merge origin/features'
         withCredentials([usernamePassword(credentialsId : 'GitHub', passwordVariable:'GIT_PASSWORD', usernameVariable:'GIT_USERNAME')]){
            sh "git push http://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/Username/Repo.git"
         }
         }}
   }
   }

   }
}

当我到达舞台(“大师合并”)时,我有以下错误

Masking supported pattern matches of $GIT_PASSWORD
[Pipeline] {
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (container shutdown)
Stage "container shutdown" skipped due to earlier failure(s)
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
groovy.lang.MissingPropertyException: No such property: GIT_PASSWORD for class: groovy.lang.Binding
    at groovy.lang.Binding.getVariable(Binding.java:63)

提前感谢您的帮助:)

qcuzuvrc

qcuzuvrc1#

我有一个答案:)
先决条件:在管理jenkins -〉管理凭证-〉jenkins -〉全局凭证(不受限制)-〉用户名和密码中创建一个凭证。用户名查询github用户名,密码查询Personal access token。ID由您决定。
编码:

stage('Master merging'){

      steps{
         script{

            // Variables for input
         if(env.BRANCH_NAME == 'features'||env.BRANCH_NAME == 'main'){
         sh 'git checkout features'
         sh 'git pull'
         sh 'git remote update'
         sh 'git fetch'
         sh 'git checkout origin/main'
         sh 'git merge features'
         sh "git config user.email \"GITHUB EMAIL\""
         sh "git config user.name \"GITHUB USERNAME\""
withCredentials([gitUsernamePassword(credentialsId:'ID you inquired in credentials')]) {

sh 'git push https://github.com/Username/Repo.git'

               }
            }
         }
      }
   }

相关问题