Declarative pipeline support for tools: CMake, custom tools

3,535 views
Skip to first unread message

Colin Bennett

unread,
Feb 16, 2017, 5:56:33 PM2/16/17
to Jenkins Users
It seems that the Declarative Pipeline (Pipeline Model Definition) does not support some important tools with the "tools" block, in particular the CMake tool and custom tools.

I tried all combinations I could find of things like

     tools {
         com
.cloudbees.jenkins.plugins.customtools.CustomTool "Ninja"
         
CustomTool "Ninja"
         com
.cloudbees.jenkins.plugins.customtools.CustomTool("Ninja")
         
CMake "CMake"
         custom
"Ninja"
         
Custom "Ninja"
         msys2
"MSYS2"
     
}

Where I have custom tools called "Ninja" and MSYS2, in addition to CMake tools.

Does anyone have an idea how to make Declarative Pipelines work with custom tools, and CMake?

Regards,
Colin

Indra Gunawan (ingunawa)

unread,
Feb 16, 2017, 6:31:23 PM2/16/17
to jenkins...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e58a613f-2bba-4270-9888-5b8592f67e2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Colin Bennett

unread,
Feb 16, 2017, 8:57:41 PM2/16/17
to Jenkins Users
Thanks for the link to that issue. But it is not really the issue I am having. I am not using the CMake build step, but only using it to get the tool in the path and get auto installers.

Same for the custom tools. Both custom tools and CMake work in the Scripted Pipeline job type but I can't get it to work in the Declarative Pipeline syntax.

Daniel Beck

unread,
Feb 17, 2017, 6:34:27 AM2/17/17
to jenkins...@googlegroups.com

> On 17.02.2017, at 02:57, Colin Bennett <sky...@gmail.com> wrote:
>
> Same for the custom tools. Both custom tools and CMake work in the Scripted Pipeline job type but I can't get it to work in the Declarative Pipeline syntax.

I think Andrew mentioned on Wednesday that tools need to have @Symbol annotations to work in Declarative Pipeline, i.e. JENKINS-37386

If so, there's no workaround. The plugins need to be adapted.

Frits van der Holst

unread,
Oct 6, 2017, 12:38:13 PM10/6/17
to Jenkins Users
Hi,

Bumped into the same problem. Tools seems to be very limited with respect to the tools supported. The work around I found is like this:
    environment {
        GROOVY_HOME
= tool name: 'Groovy-2.4.9', type: 'hudson.plugins.groovy.GroovyInstallation'
   
}
    stages
{
        stage
('Run Groovy') {
            steps
{
                bat
"${groovy_home}/bin/groovy <script.name>"
           
}
       
}
   
}

I use this for multiple tools we use (cmake, groovy, innosetup.. etc..). The tool name part:
tool name: 'Groovy-2.4.9', type: 'hudson.plugins.groovy.GroovyInstallation'
Is generated using the snippet generator.

Waiting for the final solution seems to take a lot of time so this works for me right now.
Hope it helps.

Frits.

Srujana

unread,
Oct 11, 2017, 5:22:06 PM10/11/17
to Jenkins Users
This did not work for me since the tool type I want is of customtools type: 

tool name: 'bzip2', type: 'com.cloudbees.jenkins.plugins.customtools.CustomTool'

Are there any alternatives at this point?

Thanks,
Srujana

Colin Bennett

unread,
Oct 16, 2017, 1:03:26 PM10/16/17
to Jenkins Users
The workaround of use the 'tool' function in the environment PATH assignment is working for me.

Here is an example:

pipeline {
    agent
{ label "windows" }
    environment
{
        PATH
= """${
                [
                 tool('Ninja'),
                 [tool('CMake'), 'bin'].join(File.separator),
                 [tool('MSYS2'), 'mingw64', 'bin'].join(File.separator)
                ]
                .join(File.pathSeparator) +
                File.pathSeparator
            }$PATH"""

   
}
    stages
{
        stage
("build") {
            steps
{
                bat
'cmake -G Ninja .'
                bat
'cmake --build .'
           
}
       
}
   
}
}

Some of the tools are of CustomTool type and one is CMake (but I'm not using the CMake command, just a batch/shell step to call cmake manually, so I must add it to the path).  Some have the executable in a subdirectory of the automatically-installed tool archive, e.g. CMake has cmake.exe in the 'bin' subdirectory.

The multi-line groovy interpolated string produces a cross-platform path with semicolon (Windows) or colon (Linux/other) and slash/backslash as necessary.

Joe Cavanaugh

unread,
Oct 18, 2017, 2:21:39 PM10/18/17
to Jenkins Users
Note - To make what Colin did work, you must be using declarative pipeline 1.2 or higher which has its own list of dependencies. I didn't realize this right away. 
Reply all
Reply to author
Forward
0 new messages