相关疑难解决方法(0)

我们什么时候需要围绕shell变量的花括号?

在shell脚本中,我们{}何时在扩展变量时使用?

例如,我见过以下内容:

var=10        # Declare variable

echo "${var}" # One use of the variable
echo "$var"   # Another use of the variable
Run Code Online (Sandbox Code Playgroud)

是否存在显着差异,还是只是风格?一个比另一个更受欢迎吗?

syntax bash shell curly-braces

602
推荐指数
6
解决办法
22万
查看次数

jenkins管道:代理vs节点?

jenkins管道中的代理节点之间有什么区别?

我找到了那些定义:

  • 节点:管道执行的大多数工作是在一个或多个声明的节点步骤的上下文中完成的.
  • agent:agent指令指定整个Pipeline或特定阶段在Jenkins环境中的执行位置,具体取决于agent指令的放置位置.

因此两者都用于执行管道步骤.但什么时候使用哪一个?

jenkins jenkins-pipeline

114
推荐指数
1
解决办法
6万
查看次数

Jenkinsfile声明性管道定义动态环境变量

我是jenkins管道的新手,我正在定义一个声明性语法管道,我不知道我是否可以解决我的问题,因为我找不到解决方案.

在这个例子中,我需要将一个变量传递给ansible插件(在旧版本中我使用ENV_VAR或者使用inject插件从文件中注入它,该变量来自脚本.

这是我完美的风景(但它不起作用,因为环境{}):

pipeline {
  agent { node { label 'jenkins-node'}}

  stages {
    stage('Deploy') {
      environment {
        ANSIBLE_CONFIG = '${WORKSPACE}/chimera-ci/ansible/ansible.cfg'
        VERSION = sh("python3.5 docker/get_version.py")
      }
      steps {
        ansiblePlaybook credentialsId: 'example-credential', extras: '-e version=${VERSION}', inventory: 'development', playbook: 'deploy.yml'
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了其他方法来测试env vars在其他帖子中的工作方式,例如:

pipeline {
  agent { node { label 'jenkins-node'}}

  stages {
    stage('PREPARE VARS') {
      steps {
        script {
          env['VERSION'] = sh(script: "python3.5 get_version.py")
        }
        echo env.VERSION
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

但"echo env.VERSION"返回null.

还尝试了相同的例子: - VERSION = python3.5 get_version.py …

jenkins jenkins-pipeline

45
推荐指数
3
解决办法
5万
查看次数

我怎么知道jenkins管道的哪个阶段失败了

在我的Jenkins管道中,我通常使用post声明性函数向我发送电子邮件,导致管道失败.

post函数的简单语法如下:

post {
    failure {
        mail to: 'team@example.com',
             subject: "Failed Pipeline: ${currentBuild.fullDisplayName}",
             body: "Something is wrong with ${env.BUILD_URL}"
    }
}
Run Code Online (Sandbox Code Playgroud)

在上面的电子邮件中,我还想提一下管道失败的哪个阶段(假设管道有5到6个阶段).我怎样才能做到这一点?任何帮助深表感谢.

上述要求的扩展将是向用户提供(失败的阶段)的实际错误日志,也作为失败通知电子邮件的一部分.

想法是,当用户收到来自jenkins的失败通知时,他应该知道管道的哪个阶段与错误日志一起失败.

提前致谢.

jenkins jenkins-plugins jenkins-cli jenkins-pipeline

13
推荐指数
1
解决办法
5294
查看次数

你什么时候需要花括号在Gradle中进行变量替换?

如果您的gradle.properties文件中定义了变量,那么何时需要使用花括号进行变量替换(例如"some string ${yourVariable}"),何时可以不使用(例如"some string $yourVariable").始终使用花括号是最佳做法吗?

groovy gradle variable-substitution

7
推荐指数
1
解决办法
3257
查看次数