有谁知道如何打印存储在詹金斯中的凭据?下面的脚本抛出:
Unexpected exception caught! groovy.lang.MissingPropertyException: No such property: crd for class: com.test.File
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
服务.groovy
withCredentials([usernamePassword(
credentialsId: vaultCredentialId, usernameVariable: 'ID', passwordVariable: 'CRED')]){
sh """
crd=${CRED}
for chars in `echo $crd | fold -w1`; do echo "value: $chars" ; done
"""
Run Code Online (Sandbox Code Playgroud) 在 Jenkinsfile 中,我尝试通过设置 shell 脚本的 stdOut 来设置环境变量。该脚本包含一个返回 InstanceID 的 AWS 命令:
stage('Set InstanceID') {
steps {
script {
env.IID = sh (script: 'scripts/get-node-id.sh "${params.ENVIRONMENT}" "${params.NODE}"', returnStdout: true).trim()
}
}
}
Run Code Online (Sandbox Code Playgroud)
无论我做什么或使用多少个反斜杠来转义引号,都不起作用。我收到严重的替换错误。我也尝试过不加双引号。
如果我在 shell 脚本参数中进行硬编码,它就可以正常运行。
如果我想使用此处的参数值,如何使其工作?
我正在尝试从 Jenkins 管道中的 REST API 请求信息,我已经以各种方式尝试了此代码,但我不断收到此错误:
java.lang.NoSuchMethodError: No such DSL method 'httpRequest' found among steps
Run Code Online (Sandbox Code Playgroud)
我开始认为这与我的语法有关,但我不知道是什么。谁能看到我做错了什么吗?
这是代码:
stage('Check Change No'){
steps{
script{
def response = httpRequest contentType: 'APPLICATION_JSON',
httpMode: 'GET',
validResponseCodes: '100:499',
url: "http://info-service-helm-chart-microservice-bin-deploy.apps.c01u.paas.mynet.com/v3/isDeployAlloved/123456"
echo response.status.toString()
if(response.status.toString() != "200"){
def jsonSlurper = new JsonSlurper()
def responseObject = jsonSlurper.parseText(response.getContent())
String errorMsg = responseObject.errors[0]
println "ERROR:"+ errorMsg
}
else{
println "ALL OK!!!. Change Approved."
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的 Jenkins 管道脚本中有并行阶段设置,它在不同的节点(AWS EC2 实例)上执行测试
例如
stage('E2E-PR') {
parallel {
stage('Cypress Tests 1') {
agent { label 'aws_slave_cypress' }
steps {
runE2eTests()
}
}
stage('Cypress Tests 2') {
agent { label 'aws_slave_cypress' }
steps {
runE2eTests()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想重新使用从管道开始时使用的父节点生成的签出的存储库\生成的工作空间,而不是每个并行阶段都签出它自己的副本。
我遇到了一种使用顺序阶段和阶段内嵌套阶段来跨多个阶段共享工作空间的方法,我尝试如下
parallel {
stage('Cypress Tests') {
agent { label 'aws_slave_cypress' }
stages {
stage('Cypress 1') {
steps {
runE2eTests()
}
}
stage('Cypress 2') {
steps {
runE2eTests()
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我可以从 Jenkins 构建输出中看到,只有一个 aws 实例启动并用于我的两个嵌套阶段,这并没有给我带来并行性的好处。
我也遇到过 stash\unstash …
我有两个 Jenkinsfile 作为示例: A_Jenkinsfile 的内容是:
pipeline {
agent any
stages {
stage("first") {
steps {
script {
foo = "bar"
}
sh "echo ${foo}"
}
}
stage("two") {
steps {
sh "echo ${foo}"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
另外一个是B_Jenkinsfile,其内容是:
pipeline {
agent any
stages {
stage("first") {
steps {
script {
def foo = "bar"
}
sh "echo ${foo}"
}
}
stage("two") {
steps {
sh "echo ${foo}"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我构建它们时,B_Jenkinsfile 失败,A_Jenkinsfile 成功。
在脚本块的 Jenkinsfile 中使用 def 和不使用 def …
我正在 AWS - ubuntu 上运行 jenkins 实例。作为构建过程的一部分,我需要创建 docker 映像。当管道 sh 脚本运行命令时,docker build -t ${dockerImageName} ./
它会抛出错误,打开权限被拒绝。
我已验证用户是jenkins
.dockerignore 的文件权限是-rw-r--r--