terraform-provider-jenkinsci

command module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

terraform-provider-jenkinsci

Go Report Card Build Status

release

Building The Provider

Clone the repository.

mkdir -p $GOPATH/src/github.com/terraform;
cd $GOPATH/src/github.com/terraform
git clone https://github.com/DanielMabbett/terraform-provider-jenkinsci

Enter the provider directory and build the provider. Run make or:

make build

Using The Provider

More examples are kept in the examples folder.

terraform {
  required_providers {
    jenkinsci = {
      version = "~> 0.3.0"
      source  = "DanielMabbett/jenkinsci"
    }
  }
}

provider "jenkinsci" {
  jenkins_endpoint         = "..."
  jenkins_admin_username   = "..."
  jenkins_admin_password   = "..."
  jenkins_insecure         = false
}

# Views

resource "jenkinsci_view" "view" {
  name             = "1st-view"
}

# A view with an assigned project in the view. Only works with 1 project assigned so far
resource "jenkinsci_view" "test2" {
  name             = "2nd-view"
  assigned_projects = [
    jenkinsci_project.test.name,
    jenkinsci_project.test2.name
  ]
}


# Folders

resource "jenkinsci_folder" "test" {
  name = "folder"
}


# Nested Folder
resource "jenkinsci_folder" "test-nested-folder" {
  name          = "nestedfolder"
  parent_folder = jenkinsci_folder.test.name
}

# Projects

# Simple Empty Project with nothing in it
resource "jenkinsci_project" "test" {
  name = "test-project-1a"
}

# A project with disabled features in and description added 
resource "jenkinsci_project" "test2" {
  name          = "test-project-2a"
  description   = "my test project - version 2"
  disabled      = "true"
  assigned_node = "terraform-pod"
}

# A project with additional config added 
resource "jenkinsci_project" "test3" {
  name          = "test-project-3a"
  description   = "my test project - version 3a"
  assigned_node = "terraform-pod"

  parameter {
    type  = "string"
    value = "tp-value"
    key   = "tp-key"
  }

  # If you want to add additional configuration from things such as installed plugins then you can add them as xml
  additional_config = <<XML
    <builders>
      <hudson.tasks.Shell>
        <command>
          hostname; echo "hello world";
        </command>
      </hudson.tasks.Shell>
    </builders>
    <authToken>asdadadadadasd</authToken>
  XML
}

data "template_file" "cloud-config" {
  template = "${file("${path.module}/project-template.xml")}"
  vars     = {
    authToken = "anauthtoken"
  }
}

# Simple Project in a folder
resource "jenkinsci_project" "test-in-folder" {
  name = "testprojinfolder"
  folder = jenkinsci_folder.test.name
}

# Pipelines

resource "jenkinsci_pipeline" "test" {
  name = "pipelinejob"
}

# Credentials

resource "jenkinsci_credential_secret_text" "test" {
  name        = "test"
  domain      = "_"
  scope       = "GLOBAL"
  secret      = "thevalue"
  alias_id    = "test"
  description = "some description now"
}

# Plugins

resource "jenkinsci_plugin" "terraform" {
  name = "Terraform"
  version = "1.0.9"
}

resource "jenkinsci_plugin" "ccm" {
  name = "CCM"
  version = "3.2"
}

resource "jenkinsci_plugin" "ansicolor" {
  name = "AnsiColor"
  version = "0.6.2"
}

Developing the Provider

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.13+ is required). You'll also need to correctly setup a GOPATH, as well as adding $GOPATH/bin to your $PATH.

First clone the repository to: $GOPATH/src/github.com/danielmabbett/terraform-provider-jenkinsci

mkdir -p $GOPATH/src/github.com/danielmabbett; cd $GOPATH/src/github.com/danielmabbett
git clone git@github.com:danielmabbett/terraform-provider-jenkinsci
cd $GOPATH/src/github.com/danielmabbett/terraform-provider-jenkinsci

Once inside the provider directory, you can run make tools to install the dependent tooling required to compile the provider.

At this point you can compile the provider by running make build, which will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make build
...
$ $GOPATH/bin/terraform-provider-jenkinsci
...

You can also cross-compile if necessary:

GOOS=windows GOARCH=amd64 make build

require ( google.golang.org/grpc v1.29.1 github.com/DanielMabbett/gojenkins v1.1.2 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0 github.com/hashicorp/terraform v0.12.6 )

In order to run the Unit Tests for the provider, you can run:

make test

The majority of tests in the provider are Acceptance Tests. It's possible to run the entire acceptance test suite by running make testacc - however it's likely you'll want to run a subset, which you can do using a prefix, by running:

make testacc TESTARGS='-run=mytest'

The following Environment Variables must be set in your shell prior to running acceptance tests:

  • JENKINS_ENDPOINT
  • JENKINS_ADMIN_USERNAME
  • JENKINS_ADMIN_PASSWORD
  • JENKINS_INSECURE

Known Issues

Due to some of the limitations of gojenkins, we presently:

  • Cannot delete folders that are greater than 1 layer deep (more than a folder in a folder at root)

Contributors

Contributors are welcome! If you have any problems/ideas, please post these into the issues page.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL