-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix README.md typo #4
Conversation
Thanks a lot. bTW if you happen to use this plugin, find it useful and are willing to help documenting how it works, I would be very grad to merge your PR. |
I had a go at using it and got it connected to our Jenkins server but it seemed to silently fail to create my job. I was trying to recreate an existing job that I had exported the XML for. Do you have any examples of how you've successfully used it? |
Hi James, |
I did actually get this working in the end, the issue turned out to be with our authentication proxy we have in front of jenkins I believe. I'm not seeing the <disabled>true</disabled> into my template then it works though which is probably good enough. I'm planning on creating a wrapper terraform module around this that we can use internally so people don't have to deal with the XML templates in their individual projects. This is the terraform code I'm using: provider "jenkins" {
server_url = "http://jenkins.example.com"
username = "james@example.com"
password = "password"
}
resource "jenkins_job" "job" {
name = "terraform_test"
display_name = "Terraform Test"
description = "This is a job created via terraform as a test"
disabled = true
template = <<EOF
<flow-definition plugin="workflow-job@2.29">
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.61">
<scm class="hudson.plugins.git.GitSCM" plugin="git@3.9.1">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://github.com/example/project</url>
<credentialsId>abc</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>master</name>
</hudson.plugins.git.BranchSpec>
</branches>
</scm>
<scriptPath>Jenkinsfile</scriptPath>
</definition>
</flow-definition>
EOF
} I'm guessing I will need to keep those version numbers of the workflow and git plugins in sync with what we have installed on Jenkins? Thanks again for creating this, I'm really excited to be able to manage our jobs via terraform 🤞 |
I'm glad you made it work. As a matter of fact Jenkins's REST API is so simple (poor?) that it requires you to post the exact XML it would use internally to represent the job in order to create a new one. In the end you have to use the UI, copy the generated XML, use it with terraform. The abstraction leak is so terrible that all version numbers and XML namespaces and internal field values are exposed to whomever wants to use the API. Sorry about that: you will have to keep those numbers in sync with your installed plugins and there's no way around it AFAIK. :-( BTW I started working on a tiny tool to extract a template from an existing job XML (it's called jted if I remember correctly). It's not complete but it may still help you extract variables from the template. Check it out. |
It actually seems to accept plugin references without version numbers 😄. I assume is it uses whatever version is installed. There may still be issues if the class names change I suppose but hopefully that is less likely. Like so: <flow-definition plugin="workflow-job">
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps">
<scm class="hudson.plugins.git.GitSCM" plugin="git">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://github.com/pricesearcher/terraform-jenkins-test</url>
<credentialsId>abc</credentialsId>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>master</name>
</hudson.plugins.git.BranchSpec>
</branches>
</scm>
<scriptPath>Jenkinsfile</scriptPath>
</definition>
</flow-definition> |
Cool. Hope you keep using this plugin and find it useful. |
No description provided.