我正在尝试在jobDSL中创建multibranchPipelineJob,但Jenkins文件位于默认的替代位置.我查看了文档https://jenkinsci.github.io/job-dsl-plugin/#path/multibranchPipelineJob ,我看不到这样做的方法.查看config.xml以获取手动创建的multibranchPipelineJob,scriptPath位于该部分中,但我找不到设置此方法的DSL方法.
谁能提供任何帮助,如何做到这一点?干杯
jenkins jenkins-job-dsl jenkins-pipeline multibranch-pipeline
我在Jenkins有一个关于GitHub项目的工作,我想在创建新分支或删除现有分支时触发.这可能吗?
注意:Jenkins服务器位于公司内部,因此我们不能使用GitHub的Web挂钩.
我有以下DSL结构:
freeStyleJob {
wrappers {
credentialsBinding {
[
$class:"AmazonWebServicesCredentialsBinding",
accessKeyVariable: "AWS_ACCESS_KEY_ID",
credentialsId: "your-credential-id",
secretKeyVariable: "AWS_SECRET_ACCESS_KEY"
]
}
}
steps {
// ACCESS AWS ENVIRONMENT VARIABLES HERE!
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.这样做的正确语法是什么?对于Jenkins管道,您可以:
withCredentials([[
$class: "AmazonWebServicesCredentialsBinding",
accessKeyVariable: "AWS_ACCESS_KEY_ID",
credentialsId: "your-credential-id",
secretKeyVariable: "AWS_SECRET_ACCESS_KEY"]]) {
// ACCESS AWS ENVIRONMENT VARIABLES HERE!
}
Run Code Online (Sandbox Code Playgroud)
但是这种语法在正常的DSL作业groovy中不起作用.
tl; dr如何将AmazonWebServicesCredentialsBinding插件定义的AWS凭证导出到Groovy作业DSL的环境变量中?(不是PIPELINE PLUGIN语法!)
groovy credentials amazon-web-services jenkins jenkins-job-dsl
我不能在下面的访问阶段使用先前块中设置的环境变量.
pipeline{
agent any
stages{
stage("set env variable"){
steps{
script{
env.city = "Houston"
}
}
}
}
stage("access"){
steps{
sh """
set brf = ${env.city}
echo $brf
"""
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:groovy.lang.MissingPropertyException:没有这样的属性:brf for class:groovy.lang.Binding
使用jenkins声明性管道env变量的简单方法是什么?
使用job-dsl-plugin我试图编写以前手动配置的相当数量的Jenkins作业的配置.
这些作业中的一种有多个步骤,包括使用XShell插件的一对,这不是job-dsl直接支持的.但是,我应该能够通过使用自定义"配置"块来解决这个问题.
使用http://job-dsl.herokuapp.com/上的"Job DSL playground" 我已经达到了:
job {
name 'my-job'
jdk('JDK-17')
steps {
configure { node ->
node / builders {
'hudson.plugins.xshell.XShellBuilder'(plugin: 'xshell@0.9') {
commandLine('run-me-as-the-first-build-step')
executeFromWorkingDir('true')
}
}
}
maven {
mavenInstallation('Default')
goals('clean')
goals('verify')
property('prop1', 'value1')
property('user.timezone', 'UTC')
mavenOpts('--batch-mode')
}
maven {
mavenInstallation('Default')
goals('deploy')
property('prop2', 'value2')
property('user.timezone', 'UTC')
mavenOpts('--batch-mode')
}
shell('shell-task')
configure { node ->
node / builders {
'hudson.plugins.xshell.XShellBuilder'(plugin: 'xshell@0.9') {
commandLine('run-me-as-the-last-build-step')
executeFromWorkingDir('true')
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果我只包含第一个配置块,我会在第一步位置获得第一个命令.但是当第二个(最后一个)配置块存在时,"node / builders"它再次匹配第一个元素并覆盖它,因此run-me-as-the-last-step是第一个也是唯一的XShellBuilder.我寻求的输出看起来像:
<project>
... …Run Code Online (Sandbox Code Playgroud) 我正在尝试做一系列本来应该很简单的事情,但却给我带来了很多痛苦。在较高的层次上,我想循环遍历一个数组并将每个值传递到一个 gradle 任务中,该任务应该返回一个自己的数组。然后我想使用这个数组来设置一些 Jenkins 配置。
我尝试了多种方法来实现这项工作,但这是我当前的设置:
project.ext.currentItemEvaluated = "microservice-1"
task getSnapshotDependencies {
def item = currentItemEvaluated
def snapshotDependencies = []
//this does a load of stuff like looping through gradle dependencies,
//which means this really needs to be a gradle task rather than a
//function etc. It eventually populates the snapshotDependencies array.
return snapshotDependencies
}
jenkins {
jobs {
def items = getItems() //returns an array of projects to loop through
items.each { item ->
"${item}-build" {
project.ext.currentItemEvaluated = item …Run Code Online (Sandbox Code Playgroud) 我正在从事Jenkins工作,该工作接受用户的一些参数.我遇到了一个不受欢迎的行为:在我的脚本有机会读取它们之前,Jenkins似乎正在扩展参数环境变量中的环境变量引用.
如果用户输入foo-$BUILD_NUMBER参数,我的脚本实际看到的是什么foo-123; 环境变量已扩展.如果输入值包含$$,我的脚本只能看到一个$.但是,如果它包含$variable环境中不存在的值,则该值保持不变(不会引发任何类型的错误).
这很不方便,因为它甚至发生在密码字段中,我通常使用可以包含$字符的密码生成器.我不希望我的密码可能会被默默地破坏.
我的初始测试用例如下,使用Jenkins Job Builder Groovy DSL.
new BaseJobBuilder(
jobName: 'example',
jobBuildName: 'example-${BUILD_NUMBER}',
).build(this).with {
parameters {
nonStoredPasswordParam('SERVICE_PASSWORD')
}
steps {
shell('echo "$SERVICE_PASSWORD";')
}
}
Run Code Online (Sandbox Code Playgroud)
但是,对于更简化的测试用例,我从jenkins/jenkins:ltsDocker镜像创建了一个新的Jenkins安装,在没有任何插件的情况下配置它(甚至是默认设置),并使用Web UI创建了一个等效的作业.

当我使用hello $BUILD_NUMBER $HOME worldmy参数的值运行这些作业中的任何一个时SERVICE_PASSWORD,输出会扩展变量,而不是我想要的文字值.
Started by user jeremy
Building in workspace /var/jenkins_home/workspace/jeremy
[jeremy] $ /bin/sh -xe /tmp/jenkins2451955822062381529.sh
+ echo hello 3 /var/jenkins_home world
hello 3 /var/jenkins_home world
Finished: SUCCESS
Run Code Online (Sandbox Code Playgroud)
有没有办法在Jenkins进行变量扩展/插值之前访问Jenkins的原始参数值,或以其他方式禁用或绕过这种行为? …
groovy environment-variables jenkins jenkins-plugins jenkins-job-dsl
我正在使用这个插件https://plugins.jenkins.io/sidebar-link/在 jenkins 侧栏中添加一个链接。这个插件适用于 jenkins 项目配置。现在我正在尝试添加一个管道步骤来调用这个插件。
我已经尝试了下面的代码行,但它不起作用
sidebarLinks {
link("my_url", "the title", 'image path')
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了关于此的主题,但没有找到可接受的回复。我认为 jenkins 插件没有很好的文档记录。
有人知道我如何将它与管道一起使用吗?
更新
我正在使用用 Groovy 编写的共享库。该库包含所有管道方法。
@Library('xxxx@v1.0.0') _
pipeline {
stages {
...
stage('Add side link') {
steps {
addLink()
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
共享库方面,我有一个 addLink.groovy 文件。
def call(){
properties {
sidebarLinks {
link("url", 'Title', 'icon_path')
}
}
}
Run Code Online (Sandbox Code Playgroud)
我有以下错误:
错误:<-:java.lang.IllegalArgumentException:无法为 JobPropertyStep 实例化 {properties=org.jenkinsci.plugins.workflow.cps.CpsClosure2@6b5322b}
jenkins jenkins-plugins jenkins-job-dsl jenkins-groovy jenkins-pipeline
我有以下几点:
job {
scm {
git {
remote {
url(GIT_URL)
}
branch('master')
}
}
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我希望它将“签出到特定的本地分支”设置为“主”。这是怎么做的?
我在https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java中没有找到任何指向任何可以使用的东西,但我可能错过了什么。
我将构建类型即 Maven Job 或 Freestyle 作业作为输入参数(使用构建参数化插件)并根据输入条件创建相应的作业
我的输入参数: "maven" (to create Maven job) ,else 阻止自由式作业。
if(params[build_type]=="maven"){
mavenJob('example') {
using(template_job)
scm {
svn {
location(svn_url)
}
}
}
}
freeStyleJob('example') {
using(template_job)
scm {
svn {
location(svn_url)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正面临以下错误消息,我对 groovy 很陌生,所以请原谅。期待任何建议。谢谢。
处理提供的 DSL 脚本错误:(脚本,第 1 行)没有这样的属性:类的参数:脚本