#64 Jenkins python scripts

v1.2.0.0
open
nobody
None
2023-10-27
2023-04-15
adenis
No

Can someone post the python scripts used to automate unit testing. The website only refers to the general python scripting CODESYS website. For example: how to change the output path for the xUnit file and set it to the Jenkins folder? I figured out that it can be changed in the project library manager under the parameter global variable by selecting the parameter tab. No idea how to change it programmatically in python. I am sure people have done it for CodeForge Drone and it must be similar for Jenkins. Help please.

Discussion

  • hermsen

    hermsen - 2023-04-15

    Hi,

    A small primer on how to go started. You should not change the path of the xml file via Python unless you fancy a challenge. Try changing via the supposed manner: via the new lib parameter interaction window (SP19 or newer) or change it in the .library and save it (recommended for older then SP19). The lib is open source so you may do whatever you see fit. I suggest you open the lib and explore/read it as this will help you write code for step2, monitoring the successful dump of the XML file and exit the CODESYS IDE.

    1) Create a pipeline in Jenkins to fit your project needs and call CODESYS.EXE via the CLI as per https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_commandline.html.

    2) Start CODESYS.EXE via CLI with the flags according to your needs and be sure let CODESYS execute a python script which monitors that the xUnit report file has been dumped. Be sure to refer your .project file which contains your unit tests too.

    CODESYS.exe --noUI –-skipunlicensedplugins --project="<path to your project file>" --runscript="<path to your script file which monitors the xUnit xml-file has been dumped and exits CODESYS afterwards>.py"
    

    3) You should write your CODESYS project running tests (using the coUnit Library) and change the .xml file path according to your needs, but the default may suffice. I suggest you dump the file into a static folder from which you copy the file into your WorkSpace.
    PS. If the default XML path is changed, but the file isn't written or the conroller says the file has been succesfully written but it isn't there, you are affected by a new security fix, see [ticket #63] on how to get around that (NO BUG).

    5) Your pipeline should first be tested if it runs satisfactorily, after this write your code / extend your tests.

    With kind regards

     

    Last edit: hermsen 2023-04-15
  • hermsen

    hermsen - 2023-04-15
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1 +1 @@
    -Can someone post the python scripts used to automate unit testing. The website only refers to the general python scripting CODESYS website. For example: how to change the output path for the xUnit file and set it to the Jenkins folder? I figured out that it can be changed in the project library manager under the parameter global variable by selecting the parameter tab. No idea how to change it programatically in python. I am sure people have done it for CodeForge Drone and it must be similar for Jenkins. Help please.
    +Can someone post the python scripts used to automate unit testing. The website only refers to the general python scripting CODESYS website. For example: how to change the output path for the xUnit file and set it to the Jenkins folder? I figured out that it can be changed in the project library manager under the parameter global variable by selecting the parameter tab. No idea how to change it programmatically in python. I am sure people have done it for CodeForge Drone and it must be similar for Jenkins. Help please.
    
     
  • hermsen

    hermsen - 2023-04-15
    • labels: Jenkins, python, script -->
    • status: open --> wont-fix
     
  • hermsen

    hermsen - 2023-04-15
    • status: wont-fix --> open
     
  • adenis - 2023-04-15

    Thanks for the response! I am already building my libraries and packaging them in Jenkins. I am running SP17 so I can't take advantage of the SP19 feature. I'll have a look at bug 63. Ideally, the test results would be stored in the Jenkins build folder. This would allow concurrent running of builds.
    Really what I wanted to know is if someone could share the actual python script or include it in the library or in the documentation. In my experience, the largest challenge is to come up with what you call: "your script file which monitors the xUnit xml-file has been dumped and exits CODESYS afterwards.py"
    If you have such an example file, it would help greatly!

    Also, as indicated in the counit home page, it is integrated with CForge: https://forge.codesys.com/forge/wiki/Continuous%20Integration/#run-unit-test
    I am assuming that the CForge integration uses the python script method. Can those scripts be shared?

     

    Last edit: adenis 2023-04-16

Log in to post a comment.