Portable Maven launch

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Portable Maven launch

Jochen Wiedmann

Hi,

I've got a pipeline file, that should be executable on a Windows build server, and on a Linux build server. The pipeline is launching Maven as follows:

On Linux:

    sh "mvn <MAVEN_OPTIONS>"

But on Windows, this appears not to work, so I've got to use:

   bat "mvn.cmd <MAVEN_OPTIONS>" 

Right now, I can use either of these steps, so have to choose between Windows, and Linux. Is there any possibility to get this portable? I am thinking something like

   if (isWindows()) {
       bat "mvn.cmd <MAVEN_OPTIONS>" 
   } else {
    sh "mvn <MAVEN_OPTIONS>"
   }

Thanks,

Jochen



--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/20d737c4-3763-421a-9e54-1b414f93169an%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Portable Maven launch

Geoffroy J


On Saturday, 23 January 2021 at 21:19:43 UTC+1 [hidden email] wrote:

Hi,

I've got a pipeline file, that should be executable on a Windows build server, and on a Linux build server. The pipeline is launching Maven as follows:

On Linux:

    sh "mvn <MAVEN_OPTIONS>"

But on Windows, this appears not to work, so I've got to use:

   bat "mvn.cmd <MAVEN_OPTIONS>" 

Right now, I can use either of these steps, so have to choose between Windows, and Linux. Is there any possibility to get this portable? I am thinking something like

   if (isWindows()) {
       bat "mvn.cmd <MAVEN_OPTIONS>" 
   } else {
    sh "mvn <MAVEN_OPTIONS>"
   }

Thanks,

Jochen



--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9e11dd3d-e291-4fa7-8af8-a1bb36e74a6an%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Portable Maven launch

Jochen Wiedmann
Thanks,

sounds like what I was looking for. But then: Any ideas, what's wrong in my script?

pipeline {
    agent any
    tools { 
        maven 'Maven3' 
        jdk 'Java8' 
    }
    stages {
        stage ('afw-core') {
            steps {
                withMaven(
                     // Maven installation declared in the Jenkins "Global Tool Configuration"
                     maven: 'Maven3',

                    // Use `$WORKSPACE/.repository` for local repository folder to avoid shared repositories
                    mavenLocalRepo: '.repository',
                ) {
    if (isUnix()) {
            sh 'mvn -fafw/afw-core/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
} else {
            bat 'mvn.cmd -fafw/afw-core/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
}
                }
            }
        }
        stage ('afw-bootstrap') {
            steps {
                withMaven(
                     // Maven installation declared in the Jenkins "Global Tool Configuration"
                     maven: 'Maven3',

                    // Use `$WORKSPACE/.repository` for local repository folder to avoid shared repositories
                    mavenLocalRepo: '.repository',
                ) {
    if (isUnix()) {
            sh 'mvn -fafw/afw-bootstrap/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
} else {
            bat 'mvn.cmd -fafw/afw-bootstrap/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
}
                }
            }
        }
    }
}

The error message I am getting:


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 17: Expected a step @ line 17, column 9.
                                    if (isUnix()) {
           ^
WorkflowScript: 34: Expected a step @ line 34, column 9.
                                    if (isUnix()) {
           ^

On Sunday, January 24, 2021 at 5:54:26 PM UTC+1 [hidden email] wrote:


On Saturday, 23 January 2021 at 21:19:43 UTC+1 [hidden email] wrote:

Hi,

I've got a pipeline file, that should be executable on a Windows build server, and on a Linux build server. The pipeline is launching Maven as follows:

On Linux:

    sh "mvn <MAVEN_OPTIONS>"

But on Windows, this appears not to work, so I've got to use:

   bat "mvn.cmd <MAVEN_OPTIONS>" 

Right now, I can use either of these steps, so have to choose between Windows, and Linux. Is there any possibility to get this portable? I am thinking something like

   if (isWindows()) {
       bat "mvn.cmd <MAVEN_OPTIONS>" 
   } else {
    sh "mvn <MAVEN_OPTIONS>"
   }

Thanks,

Jochen



--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e083204b-5dcd-4765-bbad-d9fa0d96878fn%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Portable Maven launch

Martin Schmude
The if statement is not a pipeline step. It has to be wrapped in a script block: 
https://www.jenkins.io/doc/book/pipeline/syntax/#script


[hidden email] schrieb am Sonntag, 24. Januar 2021 um 21:30:54 UTC+1:
Thanks,

sounds like what I was looking for. But then: Any ideas, what's wrong in my script?

pipeline {
    agent any
    tools { 
        maven 'Maven3' 
        jdk 'Java8' 
    }
    stages {
        stage ('afw-core') {
            steps {
                withMaven(
                     // Maven installation declared in the Jenkins "Global Tool Configuration"
                     maven: 'Maven3',

                    // Use `$WORKSPACE/.repository` for local repository folder to avoid shared repositories
                    mavenLocalRepo: '.repository',
                ) {
    if (isUnix()) {
            sh 'mvn -fafw/afw-core/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
} else {
            bat 'mvn.cmd -fafw/afw-core/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
}
                }
            }
        }
        stage ('afw-bootstrap') {
            steps {
                withMaven(
                     // Maven installation declared in the Jenkins "Global Tool Configuration"
                     maven: 'Maven3',

                    // Use `$WORKSPACE/.repository` for local repository folder to avoid shared repositories
                    mavenLocalRepo: '.repository',
                ) {
    if (isUnix()) {
            sh 'mvn -fafw/afw-bootstrap/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
} else {
            bat 'mvn.cmd -fafw/afw-bootstrap/pom.xml -Pjacoco -Dmaven.test.failure.ignore=true clean install'
}
                }
            }
        }
    }
}

The error message I am getting:


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 17: Expected a step @ line 17, column 9.
                                    if (isUnix()) {
           ^
WorkflowScript: 34: Expected a step @ line 34, column 9.
                                    if (isUnix()) {
           ^

On Sunday, January 24, 2021 at 5:54:26 PM UTC+1 [hidden email] wrote:


On Saturday, 23 January 2021 at 21:19:43 UTC+1 [hidden email] wrote:

Hi,

I've got a pipeline file, that should be executable on a Windows build server, and on a Linux build server. The pipeline is launching Maven as follows:

On Linux:

    sh "mvn <MAVEN_OPTIONS>"

But on Windows, this appears not to work, so I've got to use:

   bat "mvn.cmd <MAVEN_OPTIONS>" 

Right now, I can use either of these steps, so have to choose between Windows, and Linux. Is there any possibility to get this portable? I am thinking something like

   if (isWindows()) {
       bat "mvn.cmd <MAVEN_OPTIONS>" 
   } else {
    sh "mvn <MAVEN_OPTIONS>"
   }

Thanks,

Jochen



--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f318612c-c265-47eb-9546-83d1469ae717n%40googlegroups.com.