how can I run cppcheck in Jenkins?

73 views
Skip to first unread message

jesus fernandez

unread,
Mar 31, 2021, 5:43:57 AM3/31/21
to Jenkins Users
I have a playground pipeline and I am trying to start using cppcheck, but when I execute the command in the cmd (I am running windows 10) it works fine, but if executing the command inside the pipeline, it returns ```'cppcheck' is not recognized as an internal or external command``` I have installed the plugin and restarted Jenkins... what am I missing then? . This is the sample pipeline:
```
pipeline {
    agent any    
    stages {
        stage('Static Analysis') {
            steps {
                script{
                    env.FAILED_STAGE=env.STAGE_NAME
                    bat'cppcheck "D:/Source/Game"'
                }
            }
        }
    }
}
```

however the exactly same command, copied and pasted into the cmd, works just fine, analyze the folder and gives me the cppcheck.xml file. 

Also if running the pipeline like this it seems to work just fine:
```
        stage('Static Analysis') {
            steps {
                script{
                    bat'call  "C:\\Program Files\\Cppcheck\\cppcheck.exe" D:\\Source\\Game  --xml --xml-version=2 . 2> cppcheck.xml'
                }
            }
        }
```

Jérôme Godbout

unread,
Mar 31, 2021, 9:35:37 AM3/31/21
to jenkins...@googlegroups.com

Jenkins run as his own user by default, check node user or login user you are using. The cppcheck must be into that user env PATH variable.

 

I work round this to avoid spamming the PATH variable on the machine by doing env config into Jenkins, and I use that env variable to give a full path on each node.

 

https://<MyJenkinsHost>/computer/<MyNodeName>/configure

 

 

Then each node can install or put his binary into a custom path depends on the node. I use the node label to declare his capacity:

 

 

That way I run into a node that provide DOXYGEN for example, I then need to resolve the doxygen path with the env variable or if the variable is not present I assume the tool is inside the node current PATH var already (save some time for tool that are install system wide).

 

Jérôme Godbout, B. Ing.


Software / Firmware Team Lead
O: (418) 682-3636 ext.: 114  

C: (581) 777-0050 
godb...@dimonoff.com

signature_16446078

dimonoff.com

1015 Avenue Wilfrid-Pelletier, 

Québec, QC G1W 0C4, 4e étage

--
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/04691194-8864-411b-bd34-2ed8e20ab9fan%40googlegroups.com.

jesus fernandez

unread,
Apr 1, 2021, 5:47:44 AM4/1/21
to Jenkins Users
Thanks for answering,

I tried what you suggested but adding it as a env variable to the node variables does not work either. Regarding adding it to the jenkins user path I am not sure what you mean, I am not sure how to do that in windows 10, I start jenkins just by executing the .war file

Reply all
Reply to author
Forward
0 new messages