We should include some sample Jenkinsfiles with the repo which walk users through how to use the plugin with Pipeline jobs.
I can provide at least some working example with build / archive steps if needed
Is there any commit so far which show these example files?
I would really appreciate an example, struggling to set this up properly.
What excatly is needed?
Jenkins ver. 2.32.1
GitLab plugin ver. 1.4.4
Pipeline synxtax generator does not work so I am struggling when I am trying to add build trigger to jenkins file. An example would be awesome :)
properties([[$class:` 'GitLabConnectionProperty', gitLabConnection: 'Gitlab'], pipelineTriggers([<object of type com.dabsquared.gitlabjenkins.GitLabPushTrigger>])])
Got it. Correct line was:
properties([[$class: 'GitLabConnectionProperty', gitLabConnection: 'Gitlab'], pipelineTriggers([[$class: 'GitLabPushTrigger', branchFilterType: 'NameBasedFilter', triggerOnPush: true, includeBranchesSpec : 'MyBranchName', excludeBranchesSpec: '' ]])])
@JaniFuturemark #488 will make the syntax friendlier. Also included a basic example of a Jenkinsfile using the declarative syntax, more to follow!
You still need to take #475 into account though - you need to define all job properties as code the properties step.
I would like to see this coupled with a plain API-like documentation of available pipeline methods/objects (both scripted and declarative).
@jgeorgeson what would be an example of "API-like" documentation? All these doc issues are something I plan to address soon.
javadoc-like listing of the methods that I can call in my jenkinsfile. I'm finding this is the case with pipeline-enabled plugins in general so I can't link to some other plugin's documentation for reference. It seems like the _Pipeline syntax_ generator is intended to be how you find out what is available to use. However I find it to be a bit clunky as it doesn't tell me anything about the generated code. For example when I select _gitlabBuilds_ from the Sample Step combobox I'm present a text field called Build steps that takes a csv. Because it says steps I'm expecting the values to map to perhaps a _steps{}_ block in a declarative pipeline or the individual _sh_ lines in a scripted pipeline. So when I put in values that I think are appropriate I instead get this
gitlabBuilds(builds: ['echo 1', 'sh 2']) {
// some block
}
So now I'm confused how that relates to my previous notion of steps in the Jenkinsfile.
To me API-like documentation would be a list of all the methods you've exposed (like gitlabBuilds(builds: []){} takes an array of blahs and executes every command with blah applied to it in way foo.) would be helpful. That tells me _what_ I can use, examples show me how it fits in with the rest of the jenkinsfile. As it is I just end up crawling blog post in issues trackers to see how people use various plugins in their jenkinsfile.
+1 for the sample Jenkinsfile, both Scripted Jenkinsfile, and Declarative Pipeline
but still can't work with Snippet Generator
thanks to @JaniFuturemark's hint, I can create both
here's the sample for Scripted Jenkinsfile
def project_url = 'http://jenkins.example.com:8080/project/GitLabTrigger'
def project_token = 'a6eac20fae98e54b1a37c81d09276782'
properties([
gitLabConnection(project_url),
pipelineTriggers([
[
$class: 'GitLabPushTrigger',
branchFilterType: 'All',
triggerOnPush: true,
triggerOnMergeRequest: false,
ciSkip: true,
secretToken: project_token
]
])
])
node {
stage('Hello World') {
echo 'hello world'
}
}
I have done a major refactor of the README and, I hope, significantly clarified how you use the plugin with Pipeline. Please open PRs against the README if you would like to see anything improved further.
Most helpful comment
javadoc-like listing of the methods that I can call in my jenkinsfile. I'm finding this is the case with pipeline-enabled plugins in general so I can't link to some other plugin's documentation for reference. It seems like the _Pipeline syntax_ generator is intended to be how you find out what is available to use. However I find it to be a bit clunky as it doesn't tell me anything about the generated code. For example when I select _gitlabBuilds_ from the Sample Step combobox I'm present a text field called Build steps that takes a csv. Because it says steps I'm expecting the values to map to perhaps a _steps{}_ block in a declarative pipeline or the individual _sh_ lines in a scripted pipeline. So when I put in values that I think are appropriate I instead get this
So now I'm confused how that relates to my previous notion of steps in the Jenkinsfile.
To me API-like documentation would be a list of all the methods you've exposed (like
gitlabBuilds(builds: []){}takes an array of blahs and executes every command with blah applied to it in way foo.) would be helpful. That tells me _what_ I can use, examples show me how it fits in with the rest of the jenkinsfile. As it is I just end up crawling blog post in issues trackers to see how people use various plugins in their jenkinsfile.