如何在Jenkins Job DSL中结合我的种子工作?

时间:2018-05-14 10:55:58

标签: jenkins credentials dsl

我正在尝试在Jenkins中创建一个具有“身份验证令牌”作为构建触发器的作业(因此它将在git push上进行构建)。我正在使用Job DSL定义所有内容,即没有任何手动配置任何作业。

身份验证令牌在Jenkins中定义为凭据,因为我不希望此令牌硬编码,并检入SCM。

以下工作:它定义了一个 bootstrap 作业,该作业又定义了一个种子作业,其凭证绑定到环境变量; 种子作业然后定义实际的构建作业(这是重要的作业 - 我希望能够使用令牌触发的作业)。

BootStrap.groovy中:

/* 
 * Create the seed job, and bind the credential to it, for use downstream
 */

def seed_dsl = readFileFromWorkspace('./jobs/seed.groovy')

job('seed')
{
    wrappers {
        credentialsBinding {
            string ('AUTH_TOKEN','my-trigger-token')
        }
    }

     steps {
        dsl {
            text(seed_dsl)
        }
    }
}

/* Queue the job */
queue('seed')

seed.groovy:

/* 
 * Create the build job, and associate the authentication token with it
 */

job('My Useful Build Job') {

    authenticationToken(AUTH_TOKEN)

    steps {
        shell ('echo Do something useful like build my app here')
    }
}

但是,现在我有一系列 3 工作: bootstrap > 种子> 我有用的构建工作。这有一点难闻的味道 - 它很笨拙,詹金斯混乱,很难解释。

这可以简化,删除中间作业 - 即我希望能够使用定义为凭据的身份验证令牌创建作业,但分两步:种子> 我有用的构建工作

0 个答案:

没有答案