From baa09ba573e187b33641607fdbf0273aad5531bb Mon Sep 17 00:00:00 2001 From: Ajay Pathak Date: Tue, 8 Feb 2022 00:39:17 +0530 Subject: [PATCH 1/4] Updating "Adding Tools" section in EXTENDING_DOCKER.adoc --- docs/using/EXTENDING_DOCKER.adoc | 35 ++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/using/EXTENDING_DOCKER.adoc b/docs/using/EXTENDING_DOCKER.adoc index a7dc7923..02f8173a 100644 --- a/docs/using/EXTENDING_DOCKER.adoc +++ b/docs/using/EXTENDING_DOCKER.adoc @@ -47,8 +47,39 @@ See the https://github.com/jenkinsci/plugin-installation-manager-tool[Plugin Ins == Adding tools -NOTE: This documentation section has not been implemented yet. -Please feel free to submit a pull request! +To add a tool let's say `git`, you can use https://github.com/jenkinsci/configuration-as-code-plugin[Jenkins Configuration-as-Code]. +First create a Dockerfile to install required plugins for that tool as shown in link:#_installing_plugins[Installing Plugins] section. + +Most of the tool plugins in jenkins has support to automatically download tool from internet and install it which can be specified in Jenkins CasC. But If you want to manually install the tool, you can write the installation steps of the tool in the same Dockerfile, like here for `git`. + +Dockerfile:: + +[source] +---- +FROM jenkins/jenkinsfile-runner +RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* +---- + +*Note:* `git` plugin is already installed in the `jenkins/jenkinsfile-runner`, so no need to install it again with https://github.com/jenkinsci/plugin-installation-manager-tool[Plugin Installation Manager Tool]. + +Next, Creating Jenkins CasC YAML file for configuring `git` tool in jenkins. Refer to link:/demo/casc/README.md[JCasC demo] for more examples. + +jenkins.yaml:: + +[source] +---- +tool: + git: + installations: + - name: git + home: /usr/bin/git +---- +You can then run `jenkinsfile-runner` like this +[source] +---- +docker run --rm -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile -v $(pwd)/jenkins.yaml:/usr/share/jenkins/ref/casc/jenkins.yaml jenkinsfile-runner:my-image +---- +Here `jenkinsfile-runner:my-image` is custom docker image created from above Dockerfile. == Configuring Jenkins From ae157d369281395b8501652606c55487f8b92d3a Mon Sep 17 00:00:00 2001 From: Ajay Pathak Date: Wed, 16 Feb 2022 23:53:08 +0530 Subject: [PATCH 2/4] Updating Adding tools section in EXTENDING_DOCKER.adoc --- docs/using/EXTENDING_DOCKER.adoc | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/docs/using/EXTENDING_DOCKER.adoc b/docs/using/EXTENDING_DOCKER.adoc index 02f8173a..2c9b1827 100644 --- a/docs/using/EXTENDING_DOCKER.adoc +++ b/docs/using/EXTENDING_DOCKER.adoc @@ -47,10 +47,13 @@ See the https://github.com/jenkinsci/plugin-installation-manager-tool[Plugin Ins == Adding tools -To add a tool let's say `git`, you can use https://github.com/jenkinsci/configuration-as-code-plugin[Jenkins Configuration-as-Code]. -First create a Dockerfile to install required plugins for that tool as shown in link:#_installing_plugins[Installing Plugins] section. +To add a tool let's say `git`, you can use https://github.com/jenkinsci/configuration-as-code-plugin[Jenkins Configuration-as-Code]. To know more about tools in jenkins, see https://www.jenkins.io/doc/book/managing/tools/[Managing Tools]. -Most of the tool plugins in jenkins has support to automatically download tool from internet and install it which can be specified in Jenkins CasC. But If you want to manually install the tool, you can write the installation steps of the tool in the same Dockerfile, like here for `git`. +To configure a tool in jenkins, you first need to install required plugins for that tool, so you can install plugins in `jenkinsfile-runner` as shown in link:#_installing_plugins[Installing Plugins] section. As `git` plugin is already installed in the `jenkins/jenkinsfile-runner`, so no need to install it again. + +*Note:* Here `git` tool is different than `git` plugin, here `git` tool is the `git` command that jenkins internally uses to clone repositories. + +Most of the tool plugins in jenkins has support to automatically download tool from internet and install it which can be specified in Jenkins CasC, like shown in this https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos/nodejs[example]. But If you want to manually install the tool, you can write the installation steps of the tool in the same Dockerfile (that used to install plugins), like here for `git`, the preferred method is to install `git` command is with OS Package Manager. Dockerfile:: @@ -60,8 +63,6 @@ FROM jenkins/jenkinsfile-runner RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* ---- -*Note:* `git` plugin is already installed in the `jenkins/jenkinsfile-runner`, so no need to install it again with https://github.com/jenkinsci/plugin-installation-manager-tool[Plugin Installation Manager Tool]. - Next, Creating Jenkins CasC YAML file for configuring `git` tool in jenkins. Refer to link:/demo/casc/README.md[JCasC demo] for more examples. jenkins.yaml:: @@ -74,6 +75,24 @@ tool: - name: git home: /usr/bin/git ---- + +Now you can run a Jenkinsfile having `git` as a stage like given below + +Jenkinsfile:: +[source] +---- +pipeline { + agent any + stages { + stage('Print hello') { + tools {git 'git'} //optional + steps { + git branch: 'master', url: 'git-repo-url' + } + } + } +} +---- You can then run `jenkinsfile-runner` like this [source] ---- From f947573065404e7e900096f79e370a60c61453e7 Mon Sep 17 00:00:00 2001 From: Ajay Pathak Date: Wed, 16 Feb 2022 23:56:22 +0530 Subject: [PATCH 3/4] Update EXTENDING_DOCKER.adoc --- docs/using/EXTENDING_DOCKER.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/using/EXTENDING_DOCKER.adoc b/docs/using/EXTENDING_DOCKER.adoc index 2c9b1827..bcd1adcf 100644 --- a/docs/using/EXTENDING_DOCKER.adoc +++ b/docs/using/EXTENDING_DOCKER.adoc @@ -49,11 +49,11 @@ See the https://github.com/jenkinsci/plugin-installation-manager-tool[Plugin Ins To add a tool let's say `git`, you can use https://github.com/jenkinsci/configuration-as-code-plugin[Jenkins Configuration-as-Code]. To know more about tools in jenkins, see https://www.jenkins.io/doc/book/managing/tools/[Managing Tools]. -To configure a tool in jenkins, you first need to install required plugins for that tool, so you can install plugins in `jenkinsfile-runner` as shown in link:#_installing_plugins[Installing Plugins] section. As `git` plugin is already installed in the `jenkins/jenkinsfile-runner`, so no need to install it again. +To configure a tool in jenkins, you first need to install required plugins for that tool, so you can install plugins in `jenkinsfile-runner` as shown in link:#_installing_plugins[Installing Plugins] section. As `git` plugin is already present in the `jenkins/jenkinsfile-runner` docker image, so no need to install it again. *Note:* Here `git` tool is different than `git` plugin, here `git` tool is the `git` command that jenkins internally uses to clone repositories. -Most of the tool plugins in jenkins has support to automatically download tool from internet and install it which can be specified in Jenkins CasC, like shown in this https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos/nodejs[example]. But If you want to manually install the tool, you can write the installation steps of the tool in the same Dockerfile (that used to install plugins), like here for `git`, the preferred method is to install `git` command is with OS Package Manager. +Most of the tool plugins in jenkins has support to automatically download tool from internet and install it which can be specified in Jenkins CasC, like shown in this https://github.com/jenkinsci/configuration-as-code-plugin/tree/master/demos/nodejs[example]. But If you want to manually install the tool, you can write the installation steps of the tool in the same Dockerfile (that used to install plugins), like here for `git`, the preferred method to install `git` command is with OS Package Manager. Dockerfile:: From 5b72ef6076d52f6de118e2b5d80ff8db89e5cc54 Mon Sep 17 00:00:00 2001 From: Ajay Pathak Date: Fri, 18 Mar 2022 00:05:19 +0530 Subject: [PATCH 4/4] Update EXTENDING_DOCKER.adoc --- docs/using/EXTENDING_DOCKER.adoc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/using/EXTENDING_DOCKER.adoc b/docs/using/EXTENDING_DOCKER.adoc index bcd1adcf..7f20ac43 100644 --- a/docs/using/EXTENDING_DOCKER.adoc +++ b/docs/using/EXTENDING_DOCKER.adoc @@ -76,7 +76,8 @@ tool: home: /usr/bin/git ---- -Now you can run a Jenkinsfile having `git` as a stage like given below +Now you can run a Jenkinsfile having `git` as a stage like given below. +The following is a simple Jenkinsfile to Clone the git repositories using `git` tool. Jenkinsfile:: [source] @@ -84,7 +85,7 @@ Jenkinsfile:: pipeline { agent any stages { - stage('Print hello') { + stage('Clone git repository') { tools {git 'git'} //optional steps { git branch: 'master', url: 'git-repo-url' @@ -93,13 +94,15 @@ pipeline { } } ---- -You can then run `jenkinsfile-runner` like this +You can then run `jenkinsfile-runner` like the following [source] ---- docker run --rm -v $(pwd)/Jenkinsfile:/workspace/Jenkinsfile -v $(pwd)/jenkins.yaml:/usr/share/jenkins/ref/casc/jenkins.yaml jenkinsfile-runner:my-image ---- Here `jenkinsfile-runner:my-image` is custom docker image created from above Dockerfile. +Same procedure can be applied to add other tools like `ant`, `maven`, `jdk`, `nodejs`, `terraform` or any other tool in `jenkinsfile-runner` docker image. + == Configuring Jenkins //TODO: Invalid due to https://github.com/jenkinsci/jenkinsfile-runner/issues/359