简体   繁体   English

使用 Process DSL 插件 groovy 脚本创建一个新的 Jenkins 作业

[英]create a new Jenkins job by using Process DSL plugin groovy script

I need to create a Jenkins new job by copying the configurations from an existing maven project.我需要通过从现有 Maven 项目复制配置来创建 Jenkins 新作业。 I wanted to do this via a groovy script and using the I have Process DSL plugin.我想通过一个 groovy 脚本并使用 I have Process DSL 插件来做到这一点。 I have written the below script which is able to create a new job but I am getting an issue with the GIT SSH URL我已经编写了下面的脚本,它能够创建一个新作业,但是我遇到了 GIT SSH URL 的问题

String gitRepository = 'ssh://git@stash.abc.com:1111/cegp/abc-automation-test'
String buildBranch = 'develop'
String projectName = 'APMSmokeTesting'
String credentialIDGithub = '61668d1b-3336-4c4d-90d7-721017049e36'


// job definition
mavenJob(projectName) {
    logRotator {
        numToKeep(20)
    }
    wrappers {
        preBuildCleanup()
    }
    description('Build the Java project: ' + gitRepository)
    
    scm {
        git {
            branch(buildBranch)
            remote {
                github (gitRepository)
                credentials(credentialIDGithub)
            }
        }
    }
    
    triggers {
        scm('@daily')
    }
    wrappers {
        goals('clean verify -Dtags="APMSmokeTesting"')
    }
}

As per the above configuration, in the new job Source code Management the Repository URL should be ssh://git@stash.abc.com:1111/cegp/abc-automation-test.git as I need to do an SSH only.根据上述配置,在新作业源代码管理中存储库 URL应为 ssh://git@stash.abc.com:1111/cegp/abc-automation-test.git,因为我只需要执行 SSH。 But the above script is population Repository URL filed as ** https://github.com/**ssh://git@stash.abc.com:1111/cegp/abc-automation-test/ which is wrong.但是上面的脚本是作为 ** https://github.com/**ssh://git@stash.abc.com:1111/cegp/abc-automation-test/归档的人口存储库 URL ,这是错误的。 Could you please help me to resolve the same.你能帮我解决同样的问题吗?

Working code to automate job creation in Jenkins:

    String gitRepository = 'ssh://git@stash.abc.com:<port>/cegp/gsc-automation-test'
    String buildBranch = 'develop'
    String projectName = 'APMSmokeTesting'
    String credentialIDGithub = '61668d1b-3336-4c4d-90d7-721017049e36'

    
    // job definition
    mavenJob(projectName) {
        logRotator {
            numToKeep(20)
        }
        wrappers {
            preBuildCleanup()
        }
        description('Build the Java project: ' + gitRepository)
        
        scm {
            git {
                branch(buildBranch)
                remote {
                    url (gitRepository)
                    credentials(credentialIDGithub)
                }
            }
        }
        
        triggers {
            scm('@daily')
        }
        wrappers {
            goals('clean verify -Dtags="APMSmokeTesting"')
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM