opendevstack / ods-jenkins-shared-library

Shared Jenkins library which all ODS projects & components use - provisioning, SonarQube code scanning, Nexus publishing, OpenShift template based deployments and repository orchestration
Apache License 2.0
75 stars 57 forks source link

Orchestration Pipeline: Duplicate class error in Jenkinsfile #1079

Open renedupont opened 8 months ago

renedupont commented 8 months ago

Describe the bug I have two components that I wanted to release via the release manager / orchestration pipeline. In both components I had in each Jenkinsfile this:

class DatabaseConnection {
    String database
    String username
    String password
}
def dbConnection = new DatabaseConnection(database: 'postgres', username: 'postgres', password: 'secret')

Once I ran the release manager, I got a duplicate class exception and the pipeline failed because of this.

Meanwhile I fixed it by removing the above class and using a map instead in one of the components. Unfortunately the jenkins job that displayed the error was meanwhile automatically deleted so I don't have the exact exception text anymore but it was something like: Duplicate class definition for class 'DatabaseConnection'.

Again, in my case I solved it because it was easy to convert the class into a map, but in case you want to use a more complex class in several components, it is not possible to run the release manager with it. A workaround would be to name the class in each component differently or add package paths but I don't think that is a valid final solution to it.

Update: @oalyman told me the reason on why this is happening: The Groovy code written in a Jenkinsfile runs on the Jenkins controller (master) by default, not on the agents. This means that any Groovy code specified in a Jenkinsfile will be executed on the controller where Jenkins is running, rather than on the agents.

So I am not sure whether there is an easy fix since it is rather an issue happening due to the architecture of Jenkins and the Orchestration Pipeline.