Skip to content

Commit

Permalink
Create Github Page to project
Browse files Browse the repository at this point in the history
  • Loading branch information
robsonbittencourt committed Aug 13, 2017
1 parent 5e1e882 commit aaa9c07
Show file tree
Hide file tree
Showing 12 changed files with 1,309 additions and 109 deletions.
126 changes: 17 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,137 +2,45 @@

> In software engineering, don't repeat yourself (DRY) is a principle of software development aimed at reducing repetition of all kinds.
## Documentantion
The documentation with available functions can be [found here](https://robsonbittencourt.github.io/jenkins-dry-in-pipelines/doc.html).

## Goal
The goal of this project is to provide useful generic functions to use with [Shared Libraries](https://jenkins.io/doc/book/pipeline/shared-libraries/) feature of Jenkins Pipelines. These functions are often common to many pipelines causing code replication. With this grouping of functions it is possible to eliminate duplications by making pipeline files simpler and leaner.
The goal of this project is to provide useful generic functions to use with [Shared Libraries](https://jenkins.io/doc/book/pipeline/shared-libraries/) feature of Jenkins Pipelines. These functions are often common to many pipelines causing code replication. With this grouping of functions it is possible to eliminate duplications by making pipeline files simpler and leaner. See the example below. (Both produce the same result)

**Normal Jenkinsfile**
![compare](docs/images/compare1.png)

**Jenkinsfile using this project**
![compare](docs/images/compare2.png)

## How to use
It is necessary to import as functions of this project into your Jenkins. To do this, go to *Manage Jenkins » Configure System » Global Pipeline Libraries* and fill the following information.

![global-pipeline-config](images/global-pipeline-config.png)
![global-pipeline-config](docs/images/global-pipeline-config.png)

In the default version option choose the version you want to use. This project has tags following [SEMVER](http://semver.org/), you can use them to get specific versions. To always use the latest version, complete with master and the master branch will be used.

If you prefer it's not necessary check *Load implicitly* option. If you don't use this option it will be necessary import manually this script using the following instruction in top of the Jenkinsfile.

```
@Library('jenkins-dry-in-pipelines') _
```

More details can be found [here](https://jenkins.io/doc/book/pipeline/shared-libraries/#using-libraries).

The examples in this repository assume that the option has been checked, so the imports are not displayed

## Available functions

| **Name** | requestUserInputTag |
|-----------------|---------------------|
| **Description** | Stop the pipeline execution and request to user inform a tag |
| **Parameters** | None |
| **Return** | The selected tag |
| **Observation** | This function has a 10 minutes timeout. If a tag is not selected the pipeline is canceled |

**Example of use:**

```
node {
stage("Print tag") {
def tag = requestUserInputTag()
sh("echo ${tag}")
}
}
```

-------------------------------------------------------------------------------------------------------------------

| **Name** | mvn |
|-----------------|---------------------|
| **Description** | Execute a maven command |
| **Parameters** | mavenCommand, jdkName (optional), mavenName(optional) |
| **Return** | None |
| **Observation** | In command parameter *mvn* isn't necessary. *jdkName* and *mavenName* has *jdk* and *maven* as default value. If your Jenkins use another values, you should let them know. |

**Example of use:**

```
/*With default values*/
node {
stage("Maven package") {
mvn "clean package"
}
}
/*Without default values*/
node {
stage("Maven package") {
mvn("clean package") {
jdkName = "jdk8"
mavenName = "maven3.5"
}
}
}
```

-------------------------------------------------------------------------------------------------------------------

| **Name** | mvnPackage |
|-----------------|---------------------|
| **Description** | Execute maven package goal |
| **Parameters** | jdkName (optional), mavenName(optional) |
| **Return** | None |
| **Observation** | *jdkName* and *mavenName* has *jdk* and *maven* as default value. If your Jenkins use another values, you should let them know. |

**Example of use:**

```
node {
stage("Maven package") {
mvnPackage()
}
}
```

-------------------------------------------------------------------------------------------------------------------

| **Name** | mvnTest |
|-----------------|---------------------|
| **Description** | Execute maven test goal |
| **Parameters** | jdkName (optional), mavenName(optional) |
| **Return** | None |
| **Observation** | *jdkName* and *mavenName* has *jdk* and *maven* as default value. If your Jenkins use another values, you should let them know. |

**Example of use:**
If you want to use a version other than the configured version you can tell this in import.

```
node {
stage("Maven test") {
mvnTest()
}
}
@Library('jenkins-dry-in-pipelines@1.0.0') _
```

-------------------------------------------------------------------------------------------------------------------

| **Name** | mvnInstall |
|-----------------|---------------------|
| **Description** | Execute maven install goal |
| **Parameters** | jdkName (optional), mavenName(optional) |
| **Return** | None |
| **Observation** | *jdkName* and *mavenName* has *jdk* and *maven* as default value. If your Jenkins use another values, you should let them know. |

**Example of use:**
More details can be found [here](https://jenkins.io/doc/book/pipeline/shared-libraries/#using-libraries).

```
node {
stage("Maven install") {
mvnInstall()
}
}
```
The examples in the documentation assume that the option has been checked, so the imports are not displayed

## Contributing
If you have some function in your pipelines that you believe is generic enough feel free to submit a Pull Request.

In order to understand the operation of the scripts it is possible to observe the code of this project and the [documentation](https://jenkins.io/doc/book/pipeline/shared-libraries/#writing-libraries).
In order to understand the operation of the scripts it is possible to observe the code of this project and the [Jenkins Shared Libraries documentation](https://jenkins.io/doc/book/pipeline/shared-libraries/#writing-libraries).

## Meta
Robson Bittencourt - @rluizv - robson.luizv@gmail.com
Expand Down
2 changes: 2 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
theme: jekyll-theme-cayman
title: [Jenkins DRY in Pipelines]
41 changes: 41 additions & 0 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="{{ site.lang | default: " en-US " }}">

<head>
<meta charset="UTF-8">
<title>{% if page.title %}{{ page.title }} | {% endif %}{{ site.title | default: site.github.repository_name }} by {{ site.github.owner_name
}}</title>
<meta name="description" content="{{ page.description | default: site.description | default: site.github.project_tagline }}"
/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="{{ site.theme_color | default: "#335061" }}">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}">
</head>

<body>
<section class="page-header">
<h1 class="project-name">{{ site.title | default: site.github.repository_name }}</h1>
<h2 class="project-tagline">{{ site.description | default: site.github.project_tagline }}</h2>
{% if site.github.is_project_page %}
<a href="doc.html" class="btn">Documentation</a>
<a href="{{ site.github.repository_url }}" class="btn">View on GitHub</a>
{% endif %}
{% if site.show_downloads %}
<a href="{{ site.github.zip_url }}" class="btn">Download .zip</a>
<a href="{{ site.github.tar_url }}" class="btn">Download .tar.gz</a>
{% endif %}
</section>

<section class="main-content">
{{ content }}

<footer class="site-footer">
{% if site.github.is_project_page %}
<span class="site-footer-owner"><a href="{{ site.github.repository_url }}">{{ site.github.repository_name }}</a> is maintained by <a href="{{ site.github.owner_url }}">{{ site.github.owner_name }}</a>.</span> {% endif %}
<span class="site-footer-credits">This page was generated by <a href="https://pages.github.com">GitHub Pages</a>.</span>
</footer>
</section>
</body>

</html>
Loading

0 comments on commit aaa9c07

Please sign in to comment.