Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jgramoll/terraform-provider-jenkins

Terraform Provider to manage jenkins jobs configuration
https://github.com/jgramoll/terraform-provider-jenkins

cicd jenkins jenkins-jobs jenkins-pipeline terraform terraform-provider

Last synced: 2 months ago
JSON representation

Terraform Provider to manage jenkins jobs configuration

Awesome Lists containing this project

README

        

# terraform-provider-jenkins
Terraform Provider to manage jenkins jobs

## Install ##

You will need to install the binary as a [terraform third party plugin](https://www.terraform.io/docs/configuration/providers.html#third-party-plugins). Terraform will then pick up the binary from the local filesystem when you run `terraform init`.

```sh
curl -s https://raw.githubusercontent.com/jgramoll/terraform-provider-jenkins/master/install.sh | bash
```

## Usage ##

### Credentials ###

go to $jenkins_url/user/$username/configure

Add to .bash_profile

```sh
export JENKINS_ADDRESS=https://your.jenkins.server
export JENKINS_USERNAME=username
export JENKINS_TOKEN=jenkins_token_from_configure
```

### Importer ###

```sh
go get github.com/jgramoll/terraform-provider-jenkins/importer
importer --job "Name of your Job" --output my_tf_dir
```

1. Outputs terraform code to match the job
1. Prints script that will import the resources to tf state

### Resources ###

```terraform
provider "jenkins" {
address = "${var.jenkins_address}"
}

resource "jenkins_job" "main" {
name = "Premerge checks"
plugin = "[email protected]"
disabled = false

action {
type = "DeclarativeJobAction"
plugin = "[email protected]"
}

action {
type = "DeclarativeJobPropertyTrackerAction"
plugin = "[email protected]"
}

definition {
type = "CpsScmFlowDefinition"
plugin = "[email protected]"

scm {
type = "GitSCM"
plugin = "[email protected]"

config_version = "2"
script_path = "Jenkinsfile.api"
lightweight = false

user_remote_config {
refspec = "$${GERRIT_REFSPEC}"
url = "ssh://git.server/git-repo.git"
credentials_id = "123-abc"
}

branch {
name = "FETCH_HEAD"
}

extension {
type = "CleanBeforeCheckout"
}
}
}

property {
type = "PipelineTriggersJobProperty"

trigger {
type = "GerritTrigger"
plugin = "[email protected]"

server_name = "__ANY__"
silent_mode = false
silent_start_mode = false
escape_quotes = true

name_and_email_parameter_mode = "PLAIN"
commit_message_parameter_mode = "BASE64"
change_subject_parameter_mode = "PLAIN"
comment_text_parameter_mode = "BASE64"
dynamic_trigger_configuration = false

skip_vote = {
on_successful = false
on_failed = false
on_unstable = false
on_not_built = false
}

trigger_on_event {
type = "PluginChangeMergedEvent"
}

trigger_on_event {
type = "PluginPatchsetCreatedEvent"

exclude_drafts = false
exclude_trivial_rebase = false
exclude_no_code_change = false
exclude_private_state = false
exclude_wip_state = false
}

trigger_on_event {
type = "PluginDraftPublishedEvent"
}

gerrit_project {
compare_type = "PLAIN"
pattern = "bridge-skills"

branch {
compare_type = "REG_EXP"
pattern = "^(?!refs/meta/config).*$"
}

file_path {
compare_type = "ANT"
pattern = "path/to/file"
}
}
}
}

property {
type = "DatadogJobProperty"
plugin="[email protected]"

emit_on_checkout = false
}

property {
type = "BuildDiscarderProperty"

strategy {
type = "LogRotator"

days_to_keep = "30"
num_to_keep = "-1"
artifact_days_to_keep = "-1"
artifact_num_to_keep = "-1"
}
}

property {
type = "JiraProjectProperty"
plugin="[email protected]"
}

property {
type = "ParametersDefinitionProperty"

parameter {
type = "StringParameterDefinition"
name = "env"
description = "which env to target"
default_value = "false"
trim = false
}

parameter {
type = "ChoiceParameterDefinition"
name = "env"
description = "which env to target"
choices = ["1", "3", "4"]
}

parameter {
type = "BooleanParameterDefinition"
name = "env"
description = "which env to target"
default_value = ture
}
}

property {
type = "DisableConcurrentBuildsJobProperty"
}
}
```

## Development ##

### Dependencies ###

You should have a working Go environment setup. If not check out the Go [getting started](http://golang.org/doc/install) guide.

[Go modules](https://github.com/golang/go/wiki/Modules) are used for dependency management. To install all dependencies run the following:

```sh
export GO111MODULE=on
go mod vendor
```

### Link ###

```sh
go clean
go build
rm ~/.terraform.d/plugins/$(uname | tr '[:upper:]' '[:lower:]')_amd64/terraform-provider-jenkins_v1.0.0
ln ./terraform-provider-jenkins ~/.terraform.d/plugins/$(uname | tr '[:upper:]' '[:lower:]')_amd64/terraform-provider-jenkins_v1.0.0
```