Thanks Slide for the help, things are clear.
One more doubt I have, can we not set global variable which will set that
variable between different stages

For ex consider
once Unit test is passed
set variable pass = true

same variable will be used in QA test stage to start if pass = true, start
QA test

thanks
Somshekar


Regards
Somshekar C Kadam
9036660538

On Fri, Apr 20, 2018 at 8:59 PM, Slide <[email protected]> wrote:

> The other problem is that you are expecting state to be retained between
> invocations of sh.
>
>                        sh 'cd /media/usb'
> sh 'rm -rf testing'
> sh 'mkdir testing'
> sh 'cd testing'
>         git branch: 'feature', url: '[email protected]:CelestialSyste
> m/cyelp.git'
> sh 'cp develop-unit/arm/ltp.sh /media/usb; chmod 777 /media/usb/ltp.sh;'
> sh 'cp develop-unit/arm/verify.sh /media/usb; chmod 777
> /media/usb/verify.sh;'
> sh '/media/usb/ltp.sh'
> sh 'cd /media/usb'
> sh '/media/usb/verify.sh'
> sh 'cd /media/usb/results'
>
> Each call to sh is a completely separate shell script invocation, which
> means that any cd you do will not be retained on the next invocation of sh.
> If you want to do stuff like this, you should use one shell script
> invocation
>
> # clone the code into the workspace, it will be copied later
> git branch: 'feature', url: '[email protected]:CelestialSystem/cyelp.git'
>
> # run test procedure (it would be even better to put this into a shell
> script within your code base)
> sh """
> cd /media/usb
> rm -rf testing
> mkdir testing
> cd testing
> cp -r ${WORKSPACE}/cyelp ./
> cp develop-unit/arm/ltp.sh /media/usb; chmod 777 /media/usb/ltp.sh
> cp develop-unit/arm/verify.sh /media/usb; chmod 777 /media/usb/verify.sh
> /media/usb/ltp.sh
> cd /media/usb
> /media/usb/verify.sh
> cd /media/usb/results
> cp results ${WORKSPACE}
> """
> # now read the output file that was copied in the shell steps above
> output = readFile 'results'
>
> etc.
>
>
>
>
>
> On Fri, Apr 20, 2018 at 1:09 AM Somshekar C Kadam <[email protected]>
> wrote:
>
>> Hi Slide,
>>
>> One more observation, this result file is not in workspace. that is the
>> reason its always outputting 1 when we print the file content.
>> This could be root cause in my understanding.
>> I am sorry I should have mentioned this ealrier that verify script writes
>> this file on hardisk which is not part of the workspace.
>> I will try to add this in workspace hope as you said it should work
>>
>> regards
>> Somshekar
>>
>> Regards
>> Somshekar C Kadam
>> 9036660538 <(903)%20666-0538>
>>
>> On Fri, Apr 20, 2018 at 10:40 AM, Somshekar C Kadam <[email protected]
>> > wrote:
>>
>>> Hi Slide,
>>>
>>> Sorry for the delay got some personal work had to step out.
>>> Here is the full script  for test stage
>>> Here verify script writes to "result" file 0 on success and 1 on
>>> failure.
>>> I am checking on the machine its value is 0, but still when i compare
>>> value of output as mentioned by you it is till 1
>>> also below script block using awk gives value as 1 always.
>>>
>>> Any other way I need to do this.
>>>
>>> ===============================
>>>
>>>             stage(‘Test’) {
>>>                 agent {
>>>                    label 'build'
>>>                 }
>>>     environment {
>>> res = 'pass'
>>>         qapass  = 'fail'
>>>         output  = '-1'
>>>     }
>>>                 steps {
>>>
>>> sh 'cd /media/usb'
>>> sh 'rm -rf testing'
>>> sh 'mkdir testing'
>>> sh 'cd testing'
>>>         git branch: 'feature', url: '[email protected]:CelestialSyste
>>> m/cyelp.git'
>>> sh 'cp develop-unit/arm/ltp.sh /media/usb; chmod 777 /media/usb/ltp.sh;'
>>> sh 'cp develop-unit/arm/verify.sh /media/usb; chmod 777
>>> /media/usb/verify.sh;'
>>> sh '/media/usb/ltp.sh'
>>> sh 'cd /media/usb'
>>> sh '/media/usb/verify.sh'
>>> sh 'cd /media/usb/results'
>>> script {
>>>     output = readFile 'result'
>>> echo "Value of outttt is $output "
>>>     if(output == "0") {
>>> print "Unittest cases Passed"
>>>     } else {
>>>
>>> print "Unittest cases Failed"
>>>     }
>>> awk '{ if ($1 == 0 ) { print "Success"; } else print "failure" }' result
>>>
>>> }
>>>
>>> script {
>>>     sh '''
>>> awk '{ if ($1 == 0 ) { print "Success"; } else print "failure" }' result
>>>     echo 'outside the script'
>>>      '''
>>>                 }
>>>                 echo "$unitpass"
>>>                         echo 'hey man done complete'
>>>                     }
>>>                 }
>>>
>>>
>>>             stage(‘Deploy’) {
>>>                 agent {
>>>                         //echo ‘Testing..’
>>>                    label 'build'
>>>                 }
>>>                 steps {
>>>                         //echo ‘Deploying….’
>>>                         echo 'hey man done complete'
>>>
>>>                         }
>>>                     }
>>>
>>>         }
>>>         post {
>>>
>>>      failure {
>>>         mail to: '[email protected]',
>>>              subject: "Failed Pipeline: ${currentBuild.
>>> fullDisplayName}",
>>>              body: "Something is wrong with ${env.BUILD_URL}"
>>>        }
>>>      success {
>>>         mail to: '[email protected]',
>>>              subject: "Success Pipeline: ${currentBuild.
>>> fullDisplayName}",
>>>              body: "Build Completed boy  ${env.BUILD_URL}"
>>>        }
>>> }
>>> }
>>>
>>> ===========================================================
>>>
>>> thanks and regards
>>> Somshekar
>>> On Thu, 19 Apr 2018 19:39 Slide, <[email protected]> wrote:
>>>
>>>> Post your full script
>>>>
>>>> On Thu, Apr 19, 2018, 06:52 Somshekar C Kadam <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Slide,
>>>>>
>>>>> I meant always the result file has 0, using above readfile when I
>>>>> compare in if cond it always says 1, I have even echoed tha value its 
>>>>> shows
>>>>> 1, not sure why
>>>>>
>>>>> regards
>>>>> Somshekar
>>>>>
>>>>> Regards
>>>>> Somshekar C Kadam
>>>>> 9036660538 <(903)%20666-0538>
>>>>>
>>>>> On Thu, Apr 19, 2018 at 7:21 PM, Somshekar C Kadam <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> Hi Slide,
>>>>>>
>>>>>> Thanks for the inputs.
>>>>>> I did check the value of output its returning always 1, actually it
>>>>>> has value 0. not sure why?
>>>>>>
>>>>>> one more clarification can we call awk  in script { } block ?
>>>>>>
>>>>>> regards
>>>>>> Somshekar
>>>>>>
>>>>>>
>>>>>> Regards
>>>>>> Somshekar C Kadam
>>>>>> 9036660538 <(903)%20666-0538>
>>>>>>
>>>>>> On Thu, Apr 19, 2018 at 7:12 PM, Slide <[email protected]> wrote:
>>>>>>
>>>>>>> Ok, then my suggestion is fine, after readFile, the variable output
>>>>>>> has the value, so just use an if check directly in the script block of 
>>>>>>> the
>>>>>>> pipeline. script blocks are groovy scripts, so you can use most of the
>>>>>>> functionality of groovy to do what you want.
>>>>>>>
>>>>>>> On Thu, Apr 19, 2018 at 6:24 AM Somshekar C Kadam <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>> Hi Slide,
>>>>>>>>
>>>>>>>> You got it right.
>>>>>>>>
>>>>>>>> result file contains either 0 or 1 as a unittest pass or fail.
>>>>>>>> I need to read this file which contains 0 or 1 and proceed next
>>>>>>>> stage.
>>>>>>>>
>>>>>>>> thanks in advance
>>>>>>>> regards
>>>>>>>> Somshekar
>>>>>>>>
>>>>>>>> Regards
>>>>>>>> Somshekar C Kadam
>>>>>>>> 9036660538 <(903)%20666-0538>
>>>>>>>>
>>>>>>>> On Thu, Apr 19, 2018 at 6:52 PM, Slide <[email protected]>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Well, it depends on what you are expecting to happen with these
>>>>>>>>> lines:
>>>>>>>>>
>>>>>>>>> awk '{ if ($1 == 0 ) { $res = "passed" } else $res = "fail" }'
>>>>>>>>> result
>>>>>>>>>
>>>>>>>>> awk '{ if ($1 == 0 ) { print "Success"; } else print "failure" }'
>>>>>>>>> result
>>>>>>>>>
>>>>>>>>> The shell scripts don't take parameters, so what are you expecting
>>>>>>>>> to be in $1? What does the variable output contain? Will it contain 
>>>>>>>>> the 0
>>>>>>>>> or other exit code? If so, just use an if statement in the script {} 
>>>>>>>>> block
>>>>>>>>> to check the value
>>>>>>>>>
>>>>>>>>> script {
>>>>>>>>>     ...
>>>>>>>>>     output = readFile 'result'
>>>>>>>>>     if(output == "0") {
>>>>>>>>>
>>>>>>>>>     } else {
>>>>>>>>>
>>>>>>>>>    }
>>>>>>>>>
>>>>>>>>> }
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Thu, Apr 19, 2018 at 6:15 AM Somshekar C Kadam <
>>>>>>>>> [email protected]> wrote:
>>>>>>>>>
>>>>>>>>>> Hi Slide,
>>>>>>>>>>
>>>>>>>>>> First of thanks for the response. Ok understood
>>>>>>>>>>  Am not finding any documentation to do the same in jjenkinsfile.
>>>>>>>>>> Please can you point to it or any example will help
>>>>>>>>>>
>>>>>>>>>> regards
>>>>>>>>>> Somshekar
>>>>>>>>>>
>>>>>>>>>> Regards
>>>>>>>>>> Somshekar C Kadam
>>>>>>>>>> 9036660538 <(903)%20666-0538>
>>>>>>>>>>
>>>>>>>>>> On Thu, Apr 19, 2018 at 6:39 PM, Slide <[email protected]>
>>>>>>>>>> wrote:
>>>>>>>>>>
>>>>>>>>>>> You can't set res inside a shell script and have it set in the
>>>>>>>>>>> pipeline. It seems like you are trying to use shell scripts to do 
>>>>>>>>>>> things
>>>>>>>>>>> that could be done directly in the Jenkinsfile as well. Is there a 
>>>>>>>>>>> reason
>>>>>>>>>>> you are using shell scripts for that?
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Apr 19, 2018 at 1:41 AM Somshekar <[email protected]>
>>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Hi All,
>>>>>>>>>>>>
>>>>>>>>>>>> I am trying to change the value of string dependign upon the
>>>>>>>>>>>> unittest cases passed by reading a file.
>>>>>>>>>>>> For next stage to proceed I want to set the string depending
>>>>>>>>>>>> upon the value next stage qa or other stage can proceed.
>>>>>>>>>>>> but not able to change value f string in jenkins file.
>>>>>>>>>>>>
>>>>>>>>>>>> value of res is not changing at all
>>>>>>>>>>>>
>>>>>>>>>>>> also to verify I have added one more script block belwo it to
>>>>>>>>>>>> verify if able to read file proerly and its value, its working 
>>>>>>>>>>>> fine.  below
>>>>>>>>>>>> its printing failure as value is set to 1 in result file.
>>>>>>>>>>>>
>>>>>>>>>>>> not sure on this, please let me know possible solution thanks
>>>>>>>>>>>> in advance
>>>>>>>>>>>>
>>>>>>>>>>>> =====================
>>>>>>>>>>>> environment {
>>>>>>>>>>>>                         res = 'pass'
>>>>>>>>>>>>                         qapass  = 'fail'
>>>>>>>>>>>>                         output  = '-1'
>>>>>>>>>>>>                 }
>>>>>>>>>>>>
>>>>>>>>>>>> ....
>>>>>>>>>>>> ....
>>>>>>>>>>>>
>>>>>>>>>>>>  script {
>>>>>>>>>>>>                             output = readFile 'result'
>>>>>>>>>>>>                             echo "Value of output is $output"
>>>>>>>>>>>>                             echo 'inside the script'
>>>>>>>>>>>>                             sh '''
>>>>>>>>>>>>                                 awk '{ if ($1 == 0 ) { $res =
>>>>>>>>>>>> "passed" } else $res = "fail" }' result
>>>>>>>>>>>>                                 echo 'outside the script'
>>>>>>>>>>>>                                 echo "value is $res"
>>>>>>>>>>>>                              '''
>>>>>>>>>>>>                         }
>>>>>>>>>>>>  script {
>>>>>>>>>>>>                             sh '''
>>>>>>>>>>>>                                 awk '{ if ($1 == 0 ) { print
>>>>>>>>>>>> "Success"; } else print "failure" }' result
>>>>>>>>>>>>                                 echo 'outside the script'
>>>>>>>>>>>>                              '''
>>>>>>>>>>>>                         }
>>>>>>>>>>>>
>>>>>>>>>>>> ==========================
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> 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 jenkinsci-users+unsubscribe@
>>>>>>>>>>>> googlegroups.com.
>>>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>>>> https://groups.google.com/d/msgid/jenkinsci-users/
>>>>>>>>>>>> 8b5e5fd5-8e6f-486f-aa54-f5bc97aa1f03%40googlegroups.com
>>>>>>>>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/8b5e5fd5-8e6f-486f-aa54-f5bc97aa1f03%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>>>>>>> .
>>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> 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 jenkinsci-users+unsubscribe@
>>>>>>>>>>> googlegroups.com.
>>>>>>>>>>>
>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>>> https://groups.google.com/d/msgid/jenkinsci-users/
>>>>>>>>>>> CAPiUgVfvD%3DhiFmw2-RcTZhAV%3D0UAfX1VGMYdG%2B4%
>>>>>>>>>>> 2BNyMq5rNp4Q%40mail.gmail.com
>>>>>>>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVfvD%3DhiFmw2-RcTZhAV%3D0UAfX1VGMYdG%2B4%2BNyMq5rNp4Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>>>>>>> .
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> 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 [email protected].
>>>>>>>>>> To view this discussion on the web visit
>>>>>>>>>> https://groups.google.com/d/msgid/jenkinsci-users/CALbGK-q3d-
>>>>>>>>>> 9vOVGcviqS6JqnKU0U669ey7Dw7irVkZNL7XSqoQ%40mail.gmail.com
>>>>>>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/CALbGK-q3d-9vOVGcviqS6JqnKU0U669ey7Dw7irVkZNL7XSqoQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>>>>>> .
>>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> 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 [email protected].
>>>>>>>>>
>>>>>>>> To view this discussion on the web visit
>>>>>>>>> https://groups.google.com/d/msgid/jenkinsci-users/
>>>>>>>>> CAPiUgVfz8KEM9KS7Q2VP5RAai0%3D6KY1Dbig_1mvTs1T6wDNa1A%
>>>>>>>>> 40mail.gmail.com
>>>>>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVfz8KEM9KS7Q2VP5RAai0%3D6KY1Dbig_1mvTs1T6wDNa1A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>>>>> .
>>>>>>>>
>>>>>>>>
>>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>>
>>>>>>>> --
>>>>>>>> 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 [email protected].
>>>>>>>> To view this discussion on the web visit
>>>>>>>> https://groups.google.com/d/msgid/jenkinsci-users/CALbGK-
>>>>>>>> ps-XRJaG-R7jsPC-%2BbD3nZu4NJEpkJYsyA_cCT5rgrBA%40mail.gmail.com
>>>>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/CALbGK-ps-XRJaG-R7jsPC-%2BbD3nZu4NJEpkJYsyA_cCT5rgrBA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>>>> .
>>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>>
>>>>>>> --
>>>>>>> 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 [email protected].
>>>>>>> To view this discussion on the web visit
>>>>>>> https://groups.google.com/d/msgid/jenkinsci-users/
>>>>>>> CAPiUgVdy-67daooVFrLtk-wgtCt6YpJzCtGWREGK7ucBXcxq5Q%40mail.gmail.com
>>>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVdy-67daooVFrLtk-wgtCt6YpJzCtGWREGK7ucBXcxq5Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>>
>>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>>
>>>>>>
>>>>>>
>>>>> --
>>>>> 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 [email protected].
>>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>>> msgid/jenkinsci-users/CALbGK-q3%2BJrJFqpa6e6hAN4XYLfrnGvCbttpu
>>>>> R1_GXtrTjjdBQ%40mail.gmail.com
>>>>> <https://groups.google.com/d/msgid/jenkinsci-users/CALbGK-q3%2BJrJFqpa6e6hAN4XYLfrnGvCbttpuR1_GXtrTjjdBQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>>> 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 [email protected].
>>>> To view this discussion on the web visit https://groups.google.com/d/
>>>> msgid/jenkinsci-users/CAPiUgVf%2Bj2gU6-9PKh1yTPSmGGvvSLDNsCcCGD6OHQh5
>>>> eJHbtw%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVf%2Bj2gU6-9PKh1yTPSmGGvvSLDNsCcCGD6OHQh5eJHbtw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>> --
>> 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 [email protected].
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/jenkinsci-users/CALbGK-rASCLkiROwHKAkAb-
>> eRRqP4CictgPAjiscsrdF4PHAzA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/jenkinsci-users/CALbGK-rASCLkiROwHKAkAb-eRRqP4CictgPAjiscsrdF4PHAzA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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 [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/CAPiUgVcM68Dy1ZXF0SoNkGmU%
> 2BwGnyBnhbLnNk7czjSj1B3tfbA%40mail.gmail.com
> <https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVcM68Dy1ZXF0SoNkGmU%2BwGnyBnhbLnNk7czjSj1B3tfbA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CALbGK-owxV0ssqbozZMwwTGLpKo_b_0Tc_TUjuNJnE%3DDNoBj_w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to