Search code examples
jenkinsjenkins-pipelinepath-findingrollbar

Jenkins - shell script - find parameter format not correct


enter image description here hope one of you can help - I'm running a script in jenkins pipeline, so that I can upload source maps to rollbar, so I need to loop through the minified js files - I'm trying to do this with the FIND command but it keeps giving me an error: find parameter format not correct - script below:

stages {
    stage('Set correct environment link') {
        steps {
            script {
                buildTarget = params.targetEnv
                if(params.targetEnv.equals("prj1")){
                    linkTarget = "http://xxx.xxx.xx/xxx/"
                } else if(params.targetEnv.equals(.......)..etc.
    stage('Uploading source maps to Rollbar') {
        steps {
                sh ''' #!/bin/bash
                    # Save a short git hash, must be run from a git
                    # repository (or a child directory)
                    version=$(git rev-parse --short HEAD)

                    # Use the post_server_time access token, you can
                    # find one in your project access token settings
                    post_server_item=e1d04646bf614e039d0af3dec3fa03a7

                    echo "Uploading source maps for version $version!"

                    # We upload a source map for each resulting JavaScript
                    # file; the path depends on your build config
                    for path in $(find dist/renew -name "*.js"); do
                      # URL of the JavaScript file on the web server
                      url=${linkTarget}/$path

                      # a path to a corresponding source map file
                      source_map="@$path.map"

                      echo "Uploading source map for $url"

                      curl --silent --show-error https://api.rollbar.com/api/1/sourcemap \
                        -F access_token=$post_server_item \
                        -F version=$version \
                        -F minified_url=$url \
                        -F source_map=$source_map \
                        > /dev/null
                    done 
                '''
        }
    }
    stage('Deploy') {
        steps {
            echo 'Deploying....'

From Bash CLI enter image description here


Solution

  • With the help of @jeb I managed to resolve this FIND issue on jenkins by placing the absolute path for (find) in the shell script - initially it was using the windows FIND cmd, so i needed to point to cygwin find cmd

    before: for path in $(find dist/renew -name "*.js"); do

    and after: for path in $(/usr/bin/find dist/renew -name "*.js"); do

    Thaks to all that commented