Creating a Jenkins Pipeline build from a pipeline
up vote
0
down vote
favorite
I'm trying to automate the creation of a Jenkins Pipeline build from within a pipeline.
I have a pipeline which creates a Bitbucket repository and commits some code to it, including a Jenkinsfile.
I need to add another step to this pipeline to then create the Pipeline build for it, which would run the steps in the Jenkinsfile.
I think the Jobs DSL should be able to handle this but the documentation I've found for it has been very sparse, and I'm still not entirely sure if it's possible or how to do it.
Any help would be appreciated. The generated Pipeline build I would imagine just needs to have a link to the repository and be told to run the Jenkinsfile there?
jenkins jenkins-pipeline
add a comment |
up vote
0
down vote
favorite
I'm trying to automate the creation of a Jenkins Pipeline build from within a pipeline.
I have a pipeline which creates a Bitbucket repository and commits some code to it, including a Jenkinsfile.
I need to add another step to this pipeline to then create the Pipeline build for it, which would run the steps in the Jenkinsfile.
I think the Jobs DSL should be able to handle this but the documentation I've found for it has been very sparse, and I'm still not entirely sure if it's possible or how to do it.
Any help would be appreciated. The generated Pipeline build I would imagine just needs to have a link to the repository and be told to run the Jenkinsfile there?
jenkins jenkins-pipeline
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to automate the creation of a Jenkins Pipeline build from within a pipeline.
I have a pipeline which creates a Bitbucket repository and commits some code to it, including a Jenkinsfile.
I need to add another step to this pipeline to then create the Pipeline build for it, which would run the steps in the Jenkinsfile.
I think the Jobs DSL should be able to handle this but the documentation I've found for it has been very sparse, and I'm still not entirely sure if it's possible or how to do it.
Any help would be appreciated. The generated Pipeline build I would imagine just needs to have a link to the repository and be told to run the Jenkinsfile there?
jenkins jenkins-pipeline
I'm trying to automate the creation of a Jenkins Pipeline build from within a pipeline.
I have a pipeline which creates a Bitbucket repository and commits some code to it, including a Jenkinsfile.
I need to add another step to this pipeline to then create the Pipeline build for it, which would run the steps in the Jenkinsfile.
I think the Jobs DSL should be able to handle this but the documentation I've found for it has been very sparse, and I'm still not entirely sure if it's possible or how to do it.
Any help would be appreciated. The generated Pipeline build I would imagine just needs to have a link to the repository and be told to run the Jenkinsfile there?
jenkins jenkins-pipeline
jenkins jenkins-pipeline
asked 19 hours ago
James
2811312
2811312
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
Yes, Job DSL is what you need for your use case.
See this and this to help you get started.
EDIT
pipeline {
agent {
label 'slave'
}
stages{
stage('stage'){
steps {
// some other steps
jobDsl scriptText: '''pipelineJob('new-job') {
def repo = 'https://xxxxx@bitbucket.org/xxxx/dummyrepo.git'
triggers {
scm('H/5 * * * *')
}
definition {
cpsScm {
scm {
git {
remote {
url(repo)
credentials('bitbucket-jenkins-access')
}
branches('master')
scriptPath('Jenkinsfile')
extensions { }
}
}
}
}
}'''
}
}
}
}
Documentation - https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-git
Thanks!. What I can't seem to gather from this post, or the documentation, is where do I put this definition? Does it go after the Stages in the Pipeline, or after the pipeline section entirely? My current pipeline file is a 'pipeline', which has some parameters, environment variables, and stages to create a repo, run an archetype, then commit and push to the created repo's. This Jobs DSL will then create Jenkins builds to run against the generated repo's - so is this just another "stage" in my pipeline, or a separate block entirely from the 'pipeline' block? Hope this makes sense!
– James
19 hours ago
See github.com/jenkinsci/job-dsl-plugin/wiki/…
– ben5556
18 hours ago
Ok so I've read through all of the links you supplied and I'm still at a loss. There is a concept of a Job DSL written as a groovy file, but this is not the way to run one from a pipeline. There seems to be some syntax to write one in a pipeline using the pipelineJob tag, but it's unclear if this is compatible to be used WITHIN an existing Jenkinsfile that already has a pipeline tag defined, and if so, whether the pipelineJob tag goes within the pineline tag, or separately. The pipeline specific syntax also doesn't seem to ref any Jenkinsfile or repository to create.
– James
15 hours ago
See my edit above. This creates a new jenkins pipeline job 'new-job' . The new-job when triggered will checkout the repo and run the code in Jenkinsfile found in the master branch of the repo configured above. Hope this helps! Change it to suit your requirements.
– ben5556
8 hours ago
Please note though that you need to approve the script as described here - jenkins.io/doc/book/managing/script-approval/#script-approval
– ben5556
7 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Yes, Job DSL is what you need for your use case.
See this and this to help you get started.
EDIT
pipeline {
agent {
label 'slave'
}
stages{
stage('stage'){
steps {
// some other steps
jobDsl scriptText: '''pipelineJob('new-job') {
def repo = 'https://xxxxx@bitbucket.org/xxxx/dummyrepo.git'
triggers {
scm('H/5 * * * *')
}
definition {
cpsScm {
scm {
git {
remote {
url(repo)
credentials('bitbucket-jenkins-access')
}
branches('master')
scriptPath('Jenkinsfile')
extensions { }
}
}
}
}
}'''
}
}
}
}
Documentation - https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-git
Thanks!. What I can't seem to gather from this post, or the documentation, is where do I put this definition? Does it go after the Stages in the Pipeline, or after the pipeline section entirely? My current pipeline file is a 'pipeline', which has some parameters, environment variables, and stages to create a repo, run an archetype, then commit and push to the created repo's. This Jobs DSL will then create Jenkins builds to run against the generated repo's - so is this just another "stage" in my pipeline, or a separate block entirely from the 'pipeline' block? Hope this makes sense!
– James
19 hours ago
See github.com/jenkinsci/job-dsl-plugin/wiki/…
– ben5556
18 hours ago
Ok so I've read through all of the links you supplied and I'm still at a loss. There is a concept of a Job DSL written as a groovy file, but this is not the way to run one from a pipeline. There seems to be some syntax to write one in a pipeline using the pipelineJob tag, but it's unclear if this is compatible to be used WITHIN an existing Jenkinsfile that already has a pipeline tag defined, and if so, whether the pipelineJob tag goes within the pineline tag, or separately. The pipeline specific syntax also doesn't seem to ref any Jenkinsfile or repository to create.
– James
15 hours ago
See my edit above. This creates a new jenkins pipeline job 'new-job' . The new-job when triggered will checkout the repo and run the code in Jenkinsfile found in the master branch of the repo configured above. Hope this helps! Change it to suit your requirements.
– ben5556
8 hours ago
Please note though that you need to approve the script as described here - jenkins.io/doc/book/managing/script-approval/#script-approval
– ben5556
7 hours ago
add a comment |
up vote
1
down vote
Yes, Job DSL is what you need for your use case.
See this and this to help you get started.
EDIT
pipeline {
agent {
label 'slave'
}
stages{
stage('stage'){
steps {
// some other steps
jobDsl scriptText: '''pipelineJob('new-job') {
def repo = 'https://xxxxx@bitbucket.org/xxxx/dummyrepo.git'
triggers {
scm('H/5 * * * *')
}
definition {
cpsScm {
scm {
git {
remote {
url(repo)
credentials('bitbucket-jenkins-access')
}
branches('master')
scriptPath('Jenkinsfile')
extensions { }
}
}
}
}
}'''
}
}
}
}
Documentation - https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-git
Thanks!. What I can't seem to gather from this post, or the documentation, is where do I put this definition? Does it go after the Stages in the Pipeline, or after the pipeline section entirely? My current pipeline file is a 'pipeline', which has some parameters, environment variables, and stages to create a repo, run an archetype, then commit and push to the created repo's. This Jobs DSL will then create Jenkins builds to run against the generated repo's - so is this just another "stage" in my pipeline, or a separate block entirely from the 'pipeline' block? Hope this makes sense!
– James
19 hours ago
See github.com/jenkinsci/job-dsl-plugin/wiki/…
– ben5556
18 hours ago
Ok so I've read through all of the links you supplied and I'm still at a loss. There is a concept of a Job DSL written as a groovy file, but this is not the way to run one from a pipeline. There seems to be some syntax to write one in a pipeline using the pipelineJob tag, but it's unclear if this is compatible to be used WITHIN an existing Jenkinsfile that already has a pipeline tag defined, and if so, whether the pipelineJob tag goes within the pineline tag, or separately. The pipeline specific syntax also doesn't seem to ref any Jenkinsfile or repository to create.
– James
15 hours ago
See my edit above. This creates a new jenkins pipeline job 'new-job' . The new-job when triggered will checkout the repo and run the code in Jenkinsfile found in the master branch of the repo configured above. Hope this helps! Change it to suit your requirements.
– ben5556
8 hours ago
Please note though that you need to approve the script as described here - jenkins.io/doc/book/managing/script-approval/#script-approval
– ben5556
7 hours ago
add a comment |
up vote
1
down vote
up vote
1
down vote
Yes, Job DSL is what you need for your use case.
See this and this to help you get started.
EDIT
pipeline {
agent {
label 'slave'
}
stages{
stage('stage'){
steps {
// some other steps
jobDsl scriptText: '''pipelineJob('new-job') {
def repo = 'https://xxxxx@bitbucket.org/xxxx/dummyrepo.git'
triggers {
scm('H/5 * * * *')
}
definition {
cpsScm {
scm {
git {
remote {
url(repo)
credentials('bitbucket-jenkins-access')
}
branches('master')
scriptPath('Jenkinsfile')
extensions { }
}
}
}
}
}'''
}
}
}
}
Documentation - https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-git
Yes, Job DSL is what you need for your use case.
See this and this to help you get started.
EDIT
pipeline {
agent {
label 'slave'
}
stages{
stage('stage'){
steps {
// some other steps
jobDsl scriptText: '''pipelineJob('new-job') {
def repo = 'https://xxxxx@bitbucket.org/xxxx/dummyrepo.git'
triggers {
scm('H/5 * * * *')
}
definition {
cpsScm {
scm {
git {
remote {
url(repo)
credentials('bitbucket-jenkins-access')
}
branches('master')
scriptPath('Jenkinsfile')
extensions { }
}
}
}
}
}'''
}
}
}
}
Documentation - https://jenkinsci.github.io/job-dsl-plugin/#path/pipelineJob-scm-git
edited 8 hours ago
answered 19 hours ago
ben5556
1,265138
1,265138
Thanks!. What I can't seem to gather from this post, or the documentation, is where do I put this definition? Does it go after the Stages in the Pipeline, or after the pipeline section entirely? My current pipeline file is a 'pipeline', which has some parameters, environment variables, and stages to create a repo, run an archetype, then commit and push to the created repo's. This Jobs DSL will then create Jenkins builds to run against the generated repo's - so is this just another "stage" in my pipeline, or a separate block entirely from the 'pipeline' block? Hope this makes sense!
– James
19 hours ago
See github.com/jenkinsci/job-dsl-plugin/wiki/…
– ben5556
18 hours ago
Ok so I've read through all of the links you supplied and I'm still at a loss. There is a concept of a Job DSL written as a groovy file, but this is not the way to run one from a pipeline. There seems to be some syntax to write one in a pipeline using the pipelineJob tag, but it's unclear if this is compatible to be used WITHIN an existing Jenkinsfile that already has a pipeline tag defined, and if so, whether the pipelineJob tag goes within the pineline tag, or separately. The pipeline specific syntax also doesn't seem to ref any Jenkinsfile or repository to create.
– James
15 hours ago
See my edit above. This creates a new jenkins pipeline job 'new-job' . The new-job when triggered will checkout the repo and run the code in Jenkinsfile found in the master branch of the repo configured above. Hope this helps! Change it to suit your requirements.
– ben5556
8 hours ago
Please note though that you need to approve the script as described here - jenkins.io/doc/book/managing/script-approval/#script-approval
– ben5556
7 hours ago
add a comment |
Thanks!. What I can't seem to gather from this post, or the documentation, is where do I put this definition? Does it go after the Stages in the Pipeline, or after the pipeline section entirely? My current pipeline file is a 'pipeline', which has some parameters, environment variables, and stages to create a repo, run an archetype, then commit and push to the created repo's. This Jobs DSL will then create Jenkins builds to run against the generated repo's - so is this just another "stage" in my pipeline, or a separate block entirely from the 'pipeline' block? Hope this makes sense!
– James
19 hours ago
See github.com/jenkinsci/job-dsl-plugin/wiki/…
– ben5556
18 hours ago
Ok so I've read through all of the links you supplied and I'm still at a loss. There is a concept of a Job DSL written as a groovy file, but this is not the way to run one from a pipeline. There seems to be some syntax to write one in a pipeline using the pipelineJob tag, but it's unclear if this is compatible to be used WITHIN an existing Jenkinsfile that already has a pipeline tag defined, and if so, whether the pipelineJob tag goes within the pineline tag, or separately. The pipeline specific syntax also doesn't seem to ref any Jenkinsfile or repository to create.
– James
15 hours ago
See my edit above. This creates a new jenkins pipeline job 'new-job' . The new-job when triggered will checkout the repo and run the code in Jenkinsfile found in the master branch of the repo configured above. Hope this helps! Change it to suit your requirements.
– ben5556
8 hours ago
Please note though that you need to approve the script as described here - jenkins.io/doc/book/managing/script-approval/#script-approval
– ben5556
7 hours ago
Thanks!. What I can't seem to gather from this post, or the documentation, is where do I put this definition? Does it go after the Stages in the Pipeline, or after the pipeline section entirely? My current pipeline file is a 'pipeline', which has some parameters, environment variables, and stages to create a repo, run an archetype, then commit and push to the created repo's. This Jobs DSL will then create Jenkins builds to run against the generated repo's - so is this just another "stage" in my pipeline, or a separate block entirely from the 'pipeline' block? Hope this makes sense!
– James
19 hours ago
Thanks!. What I can't seem to gather from this post, or the documentation, is where do I put this definition? Does it go after the Stages in the Pipeline, or after the pipeline section entirely? My current pipeline file is a 'pipeline', which has some parameters, environment variables, and stages to create a repo, run an archetype, then commit and push to the created repo's. This Jobs DSL will then create Jenkins builds to run against the generated repo's - so is this just another "stage" in my pipeline, or a separate block entirely from the 'pipeline' block? Hope this makes sense!
– James
19 hours ago
See github.com/jenkinsci/job-dsl-plugin/wiki/…
– ben5556
18 hours ago
See github.com/jenkinsci/job-dsl-plugin/wiki/…
– ben5556
18 hours ago
Ok so I've read through all of the links you supplied and I'm still at a loss. There is a concept of a Job DSL written as a groovy file, but this is not the way to run one from a pipeline. There seems to be some syntax to write one in a pipeline using the pipelineJob tag, but it's unclear if this is compatible to be used WITHIN an existing Jenkinsfile that already has a pipeline tag defined, and if so, whether the pipelineJob tag goes within the pineline tag, or separately. The pipeline specific syntax also doesn't seem to ref any Jenkinsfile or repository to create.
– James
15 hours ago
Ok so I've read through all of the links you supplied and I'm still at a loss. There is a concept of a Job DSL written as a groovy file, but this is not the way to run one from a pipeline. There seems to be some syntax to write one in a pipeline using the pipelineJob tag, but it's unclear if this is compatible to be used WITHIN an existing Jenkinsfile that already has a pipeline tag defined, and if so, whether the pipelineJob tag goes within the pineline tag, or separately. The pipeline specific syntax also doesn't seem to ref any Jenkinsfile or repository to create.
– James
15 hours ago
See my edit above. This creates a new jenkins pipeline job 'new-job' . The new-job when triggered will checkout the repo and run the code in Jenkinsfile found in the master branch of the repo configured above. Hope this helps! Change it to suit your requirements.
– ben5556
8 hours ago
See my edit above. This creates a new jenkins pipeline job 'new-job' . The new-job when triggered will checkout the repo and run the code in Jenkinsfile found in the master branch of the repo configured above. Hope this helps! Change it to suit your requirements.
– ben5556
8 hours ago
Please note though that you need to approve the script as described here - jenkins.io/doc/book/managing/script-approval/#script-approval
– ben5556
7 hours ago
Please note though that you need to approve the script as described here - jenkins.io/doc/book/managing/script-approval/#script-approval
– ben5556
7 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372072%2fcreating-a-jenkins-pipeline-build-from-a-pipeline%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown