4

I define a custom tool in Jenkins and I would like to run it during a build. In "https://wiki.jenkins.io/display/JENKINS/Custom+Tools+Plugin" I see the following : "Then, you just need to add the tool requirement to your job's Build Environment" but I cannot find such an option anywhere. Where can I find it? Or is there another way to run the installation of the custom tool?

Ivajlo Iliev
  • 303
  • 1
  • 3
  • 19

3 Answers3

3

Is this a Pipeline? If it is, you can include it in the pipeline file under 'environment', prior to the stages, like so:

pipeline {
  agent any
  options {
    timestamps()
  }
  environment {
      TOOL = tool name: '<tool>', type:     'com.cloudbees.jenkins.plugins.customtools.CustomTool'
  }
  stages {
...
}
Sean C
  • 83
  • 1
  • 9
  • org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 5: Invalid option type "timestamps". Valid option types: [ansiColor, authorizationMatrix, buildDiscarder, catchError, checkoutToSubdirectory, disableConcurrentBuilds, disableResume, durabilityHint, lock, newContainerPerStage, overrideIndexTriggers, parallelsAlwaysFailFast, preserveStashes, quietPeriod, rateLimitBuilds, retry, script, skipDefaultCheckout, skipStagesAfterUnstable, timeout, waitUntil, warnError, withContext, withCredentials, withEnv, ws] @ line 5, column 9. timestamps() – JackOuttaBox Apr 26 '21 at 19:42
  • removed options part, then still get "ERROR: No com.cloudbees.jenkins.plugins.customtools.CustomTool named found" – JackOuttaBox Apr 26 '21 at 19:42
0

If you are using scripted pipelines you can add a tool using the 'tool' command. The following example is to add a custom tool to a scripted pipeline. The tool must already be defined through the custom-tool-plugin in your global jenkins administration.

#!/usr/bin/env groovy

node('windows') {
    stage ('prepare env ') {
       withEnv(["MY_TOOL_DIR=${tool name: 'my_tool', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'}"]){

        echo "Path to my_tool\"${MY_TOOL_DIR}\""
        bat( script: '@"%MY_TOOL_DIR%\\my_tool.exe",
             returnStdout: true)
        }
    }
}
matthias_h
  • 11,356
  • 9
  • 22
  • 40
  • Is there a way to avoid tool setup if it has been done already? @Markus Hofsetter – Ren Jul 15 '20 at 15:03
  • Tool Setup is managed by the custom tool plugin. So you can add a some code that checks if your tool is already installed in the global jenkins administration. For example you could do `if test -f "$FILE"; then echo "$FILE exists." exit 0 fi` $FILE could be the tool itself or some marker file that you create the first time that the tool is installed. – Markus Hofsetter Jul 21 '20 at 12:30
-1

In your project configuration (/job/<your-project>/configure), in the Build Environment area, there's an option to "Install custom tools". Check this and you can choose from the tools you've configured in the Global Tool Configuration (/configureTools/), and if you specified a script it will be run at the start of your build to install the tool.

enter image description here

In this example I've chosen to add the clojure tool i've configured to the build.

Conan
  • 2,288
  • 1
  • 28
  • 42
  • Are you sure this is available for pipeline jobs? I do not see a Build Environment section. This only appears to exist for standard GUI jobs. On my end I only see General, Office 365, Build Triggers, Advanced Proj. Options, and Pipeline. – Boris May 31 '19 at 22:31
  • Not sure I’m afraid, maybe @sean-c answer will help? – Conan Jun 02 '19 at 09:53
  • @Conan How do we access the `clojure` variable in the build step? – NaveenKumar Namachivayam Jan 08 '21 at 03:47
  • I think we just call it from a shell, I'm afraid we've stopped using jenkins now so I can't check. Good luck! – Conan Jan 25 '21 at 12:49