可能的解决方法之一是使用 Jenkins 的 Bitbucket OAuth 插件,该插件允许直接在 Jenkins 和 Bitbucket 之间建立连接,而无需使用应用程序密码。
或者,可以通过更新 Jenkins 中保存的 Bitbucket 应用程序密码来修复凭据的损坏。
以下是使用 Bitbucket OAuth 插件的代码示例,其中使用了 Bitbucket Personal Access Token 替换了应用程序密码:
pipeline { agent any
environment {
BITBUCKET_OAUTH_CONSUMER_KEY = credentials('BITBUCKET_CONSUMER_KEY')
BITBUCKET_OAUTH_CONSUMER_SECRET = credentials('BITBUCKET_CONSUMER_SECRET')
BITBUCKET_OAUTH_ACCESS_TOKEN_SECRET = credentials('BITBUCKET_OAUTH_ACCESS_TOKEN_SECRET')
BITBUCKET_OAUTH_ACCESS_TOKEN = credentials('BITBUCKET_OAUTH_ACCESS_TOKEN')
}
stages {
stage('Checkout') {
steps {
checkout([
$class: 'GitSCM',
branches: [[name: '*/master']],
userRemoteConfigs: [[
credentialsId: 'BITBUCKET_CREDENTIALS_ID',
url: 'https://${BITBUCKET_OAUTH_CONSUMER_KEY}:${BITBUCKET_OAUTH_ACCESS_TOKEN_SECRET}@bitbucket.org/yourusername/your-repo.git'
]]
])
}
}
stage('Build and Deploy') {
steps {
sh 'mvn clean package'
sh './deploy.sh'
}
}
}
}