Continuous Integration With TIA Portal: Setup - Siemens

Transcription

ContinuousIntegration withTIA Portal:SetupTIA Portal / Continuous /ww/en/view/109801203SiemensIndustryOnlineSupport

Legal informationLegal informationUse of application examplesApplication examples illustrate the solution of automation tasks through an interaction of severalcomponents in the form of text, graphics and/or software modules. The application examples area free service by Siemens AG and/or a subsidiary of Siemens AG ("Siemens"). They arenon-binding and make no claim to completeness or functionality regarding configuration andequipment. The application examples merely offer help with typical tasks; they do not constitutecustomer-specific solutions. You yourself are responsible for the proper and safe operation of theproducts in accordance with applicable regulations and must also check the function of therespective application example and customize it for your system.Siemens grants you the non-exclusive, non-sublicensable and non-transferable right to have theapplication examples used by technically trained personnel. Any change to the applicationexamples is your responsibility. Sharing the application examples with third parties or copying theapplication examples or excerpts thereof is permitted only in combination with your own products.The application examples are not required to undergo the customary tests and quality inspectionsof a chargeable product; they may have functional and performance defects as well as errors. It isyour responsibility to use them in such a manner that any malfunctions that may occur do notresult in property damage or injury to persons. Siemens AG 2021 All rights reservedDisclaimer of liabilitySiemens shall not assume any liability, for any legal reason whatsoever, including, withoutlimitation, liability for the usability, availability, completeness and freedom from defects of theapplication examples as well as for related information, configuration and performance data andany damage caused thereby. This shall not apply in cases of mandatory liability, for exampleunder the German Product Liability Act, or in cases of intent, gross negligence, or culpable loss oflife, bodily injury or damage to health, non-compliance with a guarantee, fraudulentnon-disclosure of a defect, or culpable breach of material contractual obligations. Claims fordamages arising from a breach of material contractual obligations shall however be limited to theforeseeable damage typical of the type of agreement, unless liability arises from intent or grossnegligence or is based on loss of life, bodily injury or damage to health. The foregoing provisionsdo not imply any change in the burden of proof to your detriment. You shall indemnify Siemensagainst existing or future claims of third parties in this connection except where Siemens ismandatorily liable.By using the application examples you acknowledge that Siemens cannot be held liable for anydamage beyond the liability provisions described.Other informationSiemens reserves the right to make changes to the application examples at any time withoutnotice. In case of discrepancies between the suggestions in the application examples and otherSiemens publications such as catalogs, the content of the other documentation shall haveprecedence.The Siemens terms of use (https://support.industry.siemens.com) shall also apply.Security informationSiemens provides products and solutions with Industrial Security functions that support the secureoperation of plants, systems, machines and networks.In order to protect plants, systems, machines and networks against cyber threats, it is necessaryto implement – and continuously maintain – a holistic, state-of-the-art industrial security concept.Siemens’ products and solutions constitute one element of such a concept.Customers are responsible for preventing unauthorized access to their plants, systems, machinesand networks. Such systems, machines and components should only be connected to anenterprise network or the Internet if and to the extent such a connection is necessary and onlywhen appropriate security measures (e.g. firewalls and/or network segmentation) are in place.For additional information on industrial security measures that may be implemented, please emens’ products and solutions undergo continuous development to make them more secure.Siemens strongly recommends that product updates are applied as soon as they are availableand that the latest product versions are used. Use of product versions that are no longersupported, and failure to apply the latest updates may increase customer’s exposure to cyberthreats.To stay informed about product updates, subscribe to the Siemens Industrial Security RSS Feedat: ous Integration - SetupEntry-ID: 109801203, V1.1, 11/20212

Table of contentsTable of contentsLegal information . 21Introduction . 41.11.21.31.41.5 Siemens AG 2021 All rights reserved2Installations . 2.3.42.3.52.3.62.3.72.42.4.12.4.23Use case. 4Variants . 5Mode of operation . 6Sequence . 7Components used . 8Installing the Continuous Integration server . 9Software . 9Setup Jenkins . 9Version control server installation . 9Software . 9Project server . 10Project Server Listen Console . 10Automation desktop installation . 11Software . 11Setup SIMATIC PLCSIM Advanced . 11Setup Project Check for TIA Portal . 11Setup Project Server Export Console . 12Setup Transforming XML . 12Execution environment for Jenkins . 12Jenkins agent . 14Engineering desktop installation . 15Software . 15Setup TIA Portal . 15Appendix . 163.13.23.33.4Service and support . 16Industry Mall . 17Links and literature . 17Change documentation . 17Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/20213

1 Introduction1Introduction1.1Use caseFigure 1-1: Continuous IntegrationAgility in automation projects Regular recording of changes to program blocks in a version management feature (TIAPortal project server, version control system, e.g. with git) Automated building and testing in a "Continuous Integration System", for example withJenkins Feedback to all stakeholders Early detection of integration problems User programs written in short cycles Test changes automatically, regularly, and in less timeBenefitsScopeThis application example demonstrates a simple workflow for implementation of parts of theContinuous Integration process with the Siemens portfolio.It offers a modular toolset as an optimized basis for customer-specific solutions.ScenarioA typical scenario begins when the user changes something in his/her automation program withTIA Portal and saves the changes in that user's version control system, e.g. the project server.These changes are detected automatically and the information is sent to the ContinuousIntegration system – in this case, the orchestration software Jenkins. Jenkins starts the testenvironment and performs the tests, for example to check against a programming style guide.The result of the tests is sent to Jenkins, adjusted for ease of analysis, and then the results areautomatically sent to the developers so that they can respond in time if necessary.Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/20214

1 Introduction1.2VariantsThe Continuous Integration process has different variants.Version managementYou have various options for versioning:1. TIA Portal project server: Entire TIA Portal projects are saved on the project server,meaning that the hardware as well as the software objects are located there.2. Version control system (VCS, e.g. git, Subversion, etc.): Software objects such as programblocks can be exported from TIA Portal and saved in a VCS. The export can be triggeredwith the Openness interface or with the TIA Portal Version Control Interface (VCI).In this example, we will use the TIA Portal project server.TestingThere are various options for testing:1. The application example "S7UnitTest" can create application tests based on PLCSIMAdvanced.2. The application example "Project check for TIA Portal" can be used to check the projectagainst the programming style guide.3. The Test Suite Advanced can perform tests against a programming style guide, in additionto application tests.This application example is based on TIA Portal V16 and the application example "ProjectCheck".Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/20215

1 Introduction1.3Mode of operationFour different components are typically used in a Continuous Integration environment to applythe Continuous Integration workflow.Figure 1-2: Network overviewEngineering desktopA Microsoft Windows desktop computer on which the user edits projects with TIA Portal.Each user has his/her own engineering desktop.Version control serverA Microsoft Windows server running the TIA Portal project server. Changes to the projects arebroadcast to the Continuous Integration server and projects are exported for the automationdesktop.A version control server can be used for all projects.Continuous integration serverA Linux or Microsoft Windows server running Jenkins. Jenkins is used to coordinate the projectassembly (building) and for testing. The user can access Jenkins from his/her engineeringdesktop via a website.A Continuous Integration server is needed for all projects.Automation desktopA Microsoft Windows desktop computer running a Jenkins agent. Jenkins uses this node toexport and test the TIA Portal project.You can set up multiple automation desktops to scale your test farm.Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/20216

1 Introduction1.4SequenceThe following sketches the sequence you will follow when you implement this applicationexample.Table 1-1: Sequence1.The user modifies a block in the TIA Portal project on his/herengineering desktop. After the change, the block is stored onthe version control server as a new revision in the TIA Portalproject server.2.In addition to the TIA Portal project server, the version controlserver also contains the applicationProject Server Listen Console, which the TIA Portal projectserver regularly checks for new projects and new revisions.When the application detects changes, a corresponding testjob is created in the Jenkins software on the ContinuousIntegration server. This is accomplished with the Jenkins API.3.The Jenkins software on the Continuous Integration servertriggers the test run on the automation desktop when batchcommands are run by a connected Jenkins client on theautomation desktop. With these commands it is possible toextract the project being tested from the version control serverand check it using test applications, such as Project Check.The results of the tests are sent to the Continuous Integrationserver.4.In the final step, the Continuous Integration server informs theusers of the engineering desktop about the result of the test.VCSVCSCISCISVCSCISContinuous Integration - SetupEntry-ID: 109801203, V1.1, 11/20217

1 Introduction1.5Components usedTable 1-2: ComponentsComponentFile nameNoteSetupdocumentation109801203 Cont Int Setup DOC V11 en.pdfThis documentProject ServerToolsdocumentation109801203 Cont Int ProjServerTools DOC V10 en.pdfProject ServerToolsDokumentationTest Runner109801203 CI TestRunner DOC V10 de.pdfTest RunnerTransformingXMLdocumentation109801203 Cont Int Transforming XML DOC V10 en.pdfTransformingXMLJenkinsdocumentation109801203 Cont Int Jenkins DOC V11 en.pdfJenkinsBAT files forsetup109801203 Cont Int Setup PROJ V11.zipBAT filesProject ServerTools109801203 Cont Int ProjServerTools PROJ V10.zipCode, DLLs,applicationsTest Runner109801203 Cont Int TestRunner PROJ V10.zipDLLs,applicationsTransformingXML109801203 Cont Int Transforming XML PROJ V10.zipCode, DLLs,applicationsReadme OSS109801203 Cont Int ToolboxforTIAPortal 1.0.0READMEOSS.html109801203 Cont Int TestRunner 1.0.0 ReadMe OSS.htmlThird-partysoftwareinformationContinuous Integration - SetupEntry-ID: 109801203, V1.1, 11/20218

2 Installations2InstallationsThe application example "Continuous Integration with TIA Portal" consists of multiplecomponents, each of which has its own documentation.OverviewThe following chapters describe the software that needs to be installed for the individualcomponents in the Continuous Integration workflow.The folder paths and access credentials in the document are only examples. You can changethe folder paths according to your installation; and you must change the access credentials.2.1Installing the Continuous Integration serverThe Continuous Integration server uses the Jenkins software system. It is used to coordinatebuilding and testing.2.1.1SoftwareThe following software is necessary on the Continuous Integration server:Table 2-1: Jenkins componentsNames2.1.2RequiredType109801203 Cont Int Jenkins DOC V10 en.pdfYesDocumentationJenkins (LTS)YesWorkplace automationJava 1.8 SDKYesFramework for JenkinsNginxYesReverse proxy for Jenkins (for Linuxinstallations)Setup JenkinsInstall Jenkins as described in the "Jenkins" chapter of the document"109801203 Cont Int Jenkins DOC V10 en.pdf" in this application example.2.2Version control server installationThe version control server is used to store the projects in a central and version-controlledmanner.2.2.1SoftwareWe will use a Microsoft Windows distribution for the version control desktop.Table 2-2: SoftwareNamesRequiredPurposeProject serverYesSource controlProject Server Listen Console from the"ProjectServerTools" applicationYesQueries from the project server regardingnew projects/revisionsContinuous Integration - SetupEntry-ID: 109801203, V1.1, 11/20219

2 Installations2.2.2Project serverInstall the project server as described in the documentation.NOTEDocumentation for setting up the project n/view/1097401412.2.3Project Server Listen ConsoleExtract the Project Server Listen Console application from the project server tools on theversion control server, for example in the folder "C:\tools\ ProjectServerListsConsole". Configurethe Project Server Listen Console as described in the application's documentation.Below are the two steps for a minimal example configuration whose variables you must modifyto match the environment. Configuration is accomplished with the Windows Command Prompt;enter the commands with the variables modified.Example configuration for Jenkins data:: Basic configuration incl. Jenkins filesSiemens.ProjectServerListenConsole.exe configure --config "C:\tools\ProjectServerListenConsole\config.xml" --jenkins https://MyJenkinsServer/ -username "Bob" --password "Bob'sPassword" --dataPath "C:\tools\ProjectServerListenConsole\data.xml" --templateJob "template-job-name" -templateLabel "TIAP "Example configuration for project server: Add project server e add -server http://myprojectserver.net:12345 --config e Project Server Listen Console must regularly check the project server for new projects andrevisions. To accomplish this, create the necessary Batch file and make it start automaticallywith the Windows Autostart function. The Batch file will run the Project Server Listen Consoleevery 60 seconds to check and write the responses from the application to a log file. Note thatthe log file can become very large. Delete it as needed.Example code:@echo off:REPEATclsecho The log is stored at ServerListenConsole.exe"listen --config "C:\tools\ProjectServerListenConsole\config.xml" "C:\tools\ProjectServerListenConsole\listener.log" 2 &1timeout /t 60goto REPEATThis example code is supplied along with the application example as the Batch file listener.bat.Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/202110

2 Installations2.3Automation desktop installationThe automation desktop is used to automatically perform work steps such the application test.2.3.1SoftwareWe will use a Microsoft Windows distribution for the automation desktop. It is connected as anode with the Continuous Integration server via the Jenkins agent.Table 2-3: SoftwareNamesRequiredPurposeS7-PLCSIM Advanced V3.0YesTesting of TIA Portal projectsTest.Console from the applicationexample "Project Check for TIAPortal"YesTesting of projectsProjectServerExportConsole from theapplication "ProjectServerTools"YesExporting projects from the project serverTransform-xmlYesTransform result fileJava 1.8 SDKYesFramework for Jenkins agentJenkins agentYesConnecting the node with the Jenkins server** not part of the application example, as it is automatically generated by Jenkins based on yourconfiguration2.3.2Setup SIMATIC PLCSIM AdvancedSIMATIC PLCSIM Advanced V3.0 is used to simulate the SIMATIC S7-1500 CPU in order toprovide the corresponding test environment.Install SIMATIC PLCSIM Advanced V3.0 as described in the documentation.NOTESIMATIC S7-1500 S7-PLCSIM Advanced V3.0 n/view/1097734842.3.3Setup Project Check for TIA PortalProject Check for TIA Portal is used to check the TIA Portal projects against a programmingstyle guide.Install the software as described:NOTEProject Check article and download for TIA n/view/109741418Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/202111

2 Installations2.3.4Setup Project Server Export ConsoleThe Project Server Export Console application will be needed to export the projects from theproject server for testing.Extract the Project Server Export Console application from the Project Server Tools on the testmachines (automation desktop), for example in the etup Transforming XMLTransforming XML is used to transform the results from various applications (e.g. Project Checkfor TIA Portal) into the JUNIT format that Jenkins reads natively.Extract the Transforming XML application on the test machine (automation desktop), forexample in the folder "C:\tools\Transforming-XML".2.3.6Execution environment for JenkinsCertain preparations have to be made so that Jenkins can automatically start the tests on theautomation desktop.To start automated processes in the most flexible manner possible, we recommend the use ofone or more Batch files. Here is how you can keep the function calls in Jenkins compact andoffload the logic to the test machines: ProjectExport.bat for exporting projects from the project server to make them ready for thetest environment. StyleCheck.bat for checking projects, for example, with the Project Check or Test Suiteapplication in TIA Portal.Other Batch files, for example for application testing or similar, are also possible.The following will list two examples of Batch files where you may have to modify the paths(marked in blue) to match your installation.Example codeset serverUrl % 1set projectName % 2set revisionId % 3set WORKSPACE % 4set ERRORLEVEL % 5set COMPUTERNAME % 6@echo offmkdir "%WORKSPACE%\logs"echo ens.ProjectServerExportConsole.exe"export --server "%serverUrl%" --project "%projectName%" -revisionId %revisionId% --targetDir "%WORKSPACE%"echo %ERRORLEVEL%rename "%WORKSPACE%\%projectName%" projectrename "%WORKSPACE%\project\*.ap16" project.ap16Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/202112

2 InstallationsThis example code is supplied along with the application example as the Batch fileProjectExport.bat. When executed, the requested project will be exported via the ProjectServer Export Console application; and the name and directory of the project will beharmonized.Depending on the handling via the Project Check or Test Runner application, one of thefollowing two batch files is used.Example code for using the "Project Check" applicationset serverUrl % 1set projectName % 2set revisionId % 3set WORKSPACE % 4set ERRORLEVEL % 5set COMPUTERNAME % 6@echo offecho kConsole.exe" -p"%WORKSPACE%\project\project.ap16" -l "%WORKSPACE%\logs\projectcheck.log" nsforming-xml\bin\xslt.exe" -i"%WORKSPACE%\logs\projectcheck.report.xml" -o"%WORKSPACE%\logs\projectcheck.junit.xml" -x 2junit.xsl" -p Hostname:"%COMPUTERNAME%"echo %ERRORLEVEL%This example code is supplied along with the application example as the Batch fileStyleCheck ProjectCheck.bat. When executed, the Project Check application will be run onthe exported project, and the result will be converted to the JUNIT format with the TransformingXML application.NOTEIf the "Project Check" application is to be used, the "StyleCheck ProjectCheck.bat" file mustbe renamed to "StyleCheck.bat".Example code for using the Test Suite for styleguide and application testingset serverUrl % 1set projectName % 2set revisionId % 3set WORKSPACE % 4set ERRORLEVEL % 5set COMPUTERNAME % 6@echo offecho sole.exe" --debug --logfile%WORKSPACE%\logs\testrunner.log --report %WORKSPACE%\logs\testrunner.junit.xml--format JUNIT HUDSON --project %WORKSPACE%\project\project.ap17 --testapplication all --test-style allecho %ERRORLEVEL%Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/202113

2 InstallationsThis sample code is supplied as a batch file StyleCheck TestSuite.bat with the applicationsample. When executed, the test cases of the Test Suite are executed on the exported projectand the result is returned. The Test Suite can be called automatically up from TIA Portal V17.NOTE2.3.7If the test cases of the Test Suite are to be used, the file "StyleCheck TestSuite.bat" must berenamed to "StyleCheck.bat".Jenkins agentSo that Jenkins can run the commands on the respective test machines (automation desktop),the test machines must be connected with Jenkins. This is accomplished with the so-calledJenkins agents, which you can launch via the website for your Jenkins installation whenselecting the corresponding node.For more information on installation, refer to the chapter entitled "Connecting Jenkins agents" inthe documentation:Java environment variableTo run the Jenkins agent, a Java environment variable must be created by the installationprogram. If the Jenkins agent is not started, check whether the environment variable was set;create it if necessary. Navigate to the Control Panel, then to System Properties, thenEnvironment Variables. If necessary, enter the system variable "JAVA HOME" with the pathfrom the Java installation directory.Figure 2-1: System settingsContinuous Integration - SetupEntry-ID: 109801203, V1.1, 11/202114

2 InstallationsFigure 2-2: Edit System Variable2.4Engineering desktop installation2.4.1SoftwareWe will use a Microsoft Windows distribution for the engineering desktop.Table 2-4: SoftwareNames2.4.2RequiredPurpose.NET Framework 3.5YesFramework for TIA PortalTIA Portal V16YesCreating TIA Portal projectsSetup TIA PortalTIA Portal is used to create and modify automation projects.Install TIA Portal as described in the documentation.NOTESIMATIC STEP 7 Basic/Professional V16 n/view/109773506SIMATIC STEP 7 Basic/Professional V17 n/view/109798671Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/202115

3 Appendix3Appendix3.1Service and supportIndustry Online SupportDo you have any questions or need assistance?Siemens Industry Online Support offers round the clock access to our entire service and supportknow-how and portfolio.The Industry Online Support is the central address for information about our products, solutionsand services.Product information, manuals, downloads, FAQs, application examples and videos – allinformation is accessible with just a few mouse clicks:support.industry.siemens.comTechnical SupportThe Technical Support of Siemens Industry provides you fast and competent support regardingall technical queries with numerous tailor-made offers– ranging from basic support to individual support contracts.Please send queries to Technical Support via Web form:siemens.com/SupportRequestSITRAIN – Digital Industry AcademyWe support you with our globally available training courses for industry with practicalexperience, innovative learning methods and a concept that’s tailored to the customer’s specificneeds.For more information on our offered trainings and courses, as well as their locations and dates,refer to our web page:siemens.com/sitrainService offerOur range of services includes the following: Plant data services Spare parts services Repair services On-site and maintenance services Retrofitting and modernization services Service programs and contractsYou can find detailed information on our range of services in the service catalog web page:support.industry.siemens.com/cs/scIndustry Online Support appYou will receive optimum support wherever you are with the "Siemens Industry Online Support"app. The app is available for iOS and 067Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/202116

3 Appendix3.2Industry MallThe Siemens Industry Mall is the platform on which the entire siemens Industry product portfoliois accessible. From the selection of products to the order and the delivery tracking, the IndustryMall enables the complete purchasing processing – directly and independently of time andlocation:mall.industry.siemens.com3.3Links and literatureTable 3-1No.3.4Subject\1\Siemens Industry Online Supporthttps://support.industry.siemens.com\2\Link to the article page of this application en/view/109801203\3\TIA Portal w/en/view/65601780\4\TIA Portal Test Suite - n/view/109779356\5\S7UnitTest: Automated testing with SIMATIC S7-PLCSIM /en/view/109746405\6\Project Check for TIA Portal: Check against programming style n/view/109741418Change documentationTable 3-2VersionDateV1.008/2021V1.111/2021Continuous Integration - SetupEntry-ID: 109801203, V1.1, 11/2021ModificationsFirst versionCorrection in batch files and documentation17

When the application detects changes, a corresponding test job is created in the Jenkins software on the Continuous Integration server. This is accomplished with the Jenkins API. 3. The Jenkins software on the Continuous Integration server triggers the test run on the automation desktop when batch commands are run by a connected Jenkins client .