Your pushOneGame.sh should be marked executable by the shell account
running the script - most likely the “go” user. It currently isn’t.

— Ram

On Mon, 22 Feb 2021 at 7:26 AM, Gabriel Callaghan <
[email protected]> wrote:

> [go] Task: /bin/sh -x ./gocd/game-deploy/pushGames.shtook: 0.130s
> + curl https://{COMPANY
> NAME}/go/api/admin/pipeline_groups/PHY-Test-Deploy -H Authorization: Bearer
> ****** -H Accept: application/vnd.go.cd.v1+json
> + jq -r .pipelines[] | select(.name | contains("Games-")).name
> % Total % Received % Xferd Average Speed Time Time Time Current
> Dload Upload Total Spent Left Speed
> 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
> 100 11098 0 11098 0 0 99089 0 --:--:-- --:--:-- --:--:-- 99089
> + + readcat line
> testEnvGamesList.txt
> + echo The current pipeline is: Games-AcesHigh-PHY-Test
> + ./gocd/game-deploy/pushOneGame.sh Games-AcesHigh-PHY-Test
> The current pipeline is: Games-AcesHigh-PHY-Test
> ./gocd/game-deploy/pushGames.sh: 13: ./gocd/game-deploy/pushGames.sh:
> ./gocd/game-deploy/pushOneGame.sh: Permission denied
> + read line
> The current pipeline is: Games-CandyCash-PHY-Test
> + echo The current pipeline is: Games-CandyCash-PHY-Test
> + ./gocd/game-deploy/pushOneGame.sh Games-CandyCash-PHY-Test
> ./gocd/game-deploy/pushGames.sh: 13: ./gocd/game-deploy/pushGames.sh:
> ./gocd/game-deploy/pushOneGame.sh: Permission denied (this goes on to list
> all the other games, i've removed their output to reduce clutter but they
> all say the same things as the above 2 game output).
>
> + rm testEnvGamesList.txt
> [go] Task status: passed, took: 0.130s
> [go] Current job status: passed
>
>
> On Mon, Feb 22, 2021 at 12:13 PM Marques Lee <[email protected]>
> wrote:
>
>> Can you change your task config invoke the script with bash -x and paste
>> the exact output?
>>
>> That is:
>>
>> Command: /bin/bash
>> Args:
>>   -x
>>   /path/to/your/script.sh
>>
>>
>> On Sun, Feb 21, 2021 at 2:56 PM Gabriel Callaghan <
>> [email protected]> wrote:
>>
>>> Hi,
>>>
>>> Thank you all for your helpful comments - I have written them down in my
>>> notebook to make sure that I can retain what I've learned here. The
>>> authentication problem is fixed, it seems that there may have been a
>>> whitespace in there. Have used a GOCD token which works.
>>>
>>> My next problem is "Permission denied". I had originally thought this
>>> meant that my authentication was wrong, but after I went thru and put the
>>> new token in and checked, it seems that the auth isn't the main problem. I
>>> am running a script to pull the pipelines from a group, and to approve all
>>> of them (if they haven't been approved already). If you guys have some free
>>> time, could I please ask for your help on this?
>>>
>>> *My first script (pushGames.sh):*
>>>
>>> #! /bin/bash
>>>
>>> curl "https:// {companyName}
>>> /go/api/admin/pipeline_groups/${PIPELINE_GROUP}" \
>>>        -H "Authorization: Bearer ${GOCD_ACCESS_TOKEN}" \
>>>        -H 'Accept: application/vnd.go.cd.v1+json' \
>>> | jq -r '.pipelines[] | select(.name | contains("Games-")).name'   >
>>> testEnvGamesList.txt
>>>
>>> cat testEnvGamesList.txt | while read line
>>>
>>> do
>>>
>>> echo The current pipeline is: $line
>>> ./gocd/game-deploy/pushOneGame.sh $line
>>>
>>> done
>>>
>>> rm testEnvGamesList.txt
>>>
>>>
>>> *My second script (pushOneGame.sh):*
>>>
>>> #! /bin/bash
>>>
>>> fetchPipelineHistory=$( curl " {companyName}
>>> /go/api/stages/$1/Approve/history" \
>>>       -H "Authorization: Bearer ${GOCD_ACCESS_TOKEN}" \
>>>       -H 'Accept: application/vnd.go.cd.v2+json')
>>>
>>>
>>> getResultOfCurrentStage=$( echo $fetchPipelineHistory | jq -r
>>> '.stages[].result')
>>>
>>> counter=$( echo $fetchPipelineHistory | jq -r '.stages[0].counter')
>>>
>>> if [ "$getResultOfCurrentStage" != "Passed" ]
>>> then
>>>
>>> echo "https:// {companyName} /go/api/stages/$1/$counter/Approve/run"
>>>
>>> curl "https:// {companyName} /go/api/stages/$1/$counter/Approve/run" \
>>>       -H "Authorization: Bearer ${GOCD_ACCESS_TOKEN}" \
>>>       -H 'X-GoCD-Confirm: true' \
>>>       -H 'Accept: application/vnd.go.cd.v2+json' \
>>>       -X POST
>>>
>>> fi
>>>
>>>
>>> I am running these in the task config:
>>>
>>> Command: /bin/sh
>>>
>>> Arguments: ./{companyName}/game-deploy/pushGames.sh
>>>
>>> Both scripts are in the game-deploy folder.
>>>
>>> When running this in VS Code (I have it set up to use LF for my end of
>>> line so should work with GOCD and Bash), it works. In VScode, I run the
>>> "pushOneGame.sh" script, replacing $1 with the name of one pipeline. This
>>> works. However, when leaving it as code inside GOCD, it gives me the
>>> "permission denied". What did I miss here? I went to Admin > Security >
>>> Role config and checked that I was assigned the dev role. There is a
>>> message saying the plugins do not support role based authorization. Does
>>> this mean I need to request to be given Admin role to check?
>>>
>>> @fenn, thanks for linking me to some learning resources, I've saved them
>>> and will try to look into them when I am not on work hours.
>>>
>>> Cheers,
>>> Gabes.
>>>
>>> On Mon, Feb 22, 2021 at 7:17 AM Fenn <[email protected]> wrote:
>>>
>>>> GoCD borrows from Java standards / defacto standards and also from
>>>> Linux standards / defacto standards.  It may not be convenient but
>>>> learning something about shell notation and Java prior art (e.g. Ant)
>>>> can be useful.  The best books I can recommend to learn Linux / Unix
>>>> shell are Unix Power Tools and Unix in a Nutshell.
>>>>
>>>> https://www.goodreads.com/book/show/172314.UNIX_Power_Tools
>>>>
>>>> https://www.goodreads.com/book/show/331673.UNIX_in_a_Nutshell
>>>>
>>>> Everything you ever wanted to know about the Linux shell (bash) may be
>>>> found in the man page (Linux Manual Page) a copy of which is here:
>>>>
>>>> https://linux.die.net/man/1/bash
>>>>
>>>> But it is not an easy read for a beginner.
>>>>
>>>> You might also want to google for "bash tutorial" or "bash beginner
>>>> tutorial" to get the hang of things.  GoCD uses bash on Linux.
>>>>
>>>> Once you understand how bash works some of these GoCD behaviors might
>>>> make more sense.
>>>>
>>>> It also helps to understand Java prior art such as Apache Ant.  Ant
>>>> documentation on how properties (and environment variables) are used
>>>> is here:
>>>>
>>>> https://ant.apache.org/manual/properties.html
>>>>
>>>> https://ant.apache.org/manual/Tasks/property.html
>>>>
>>>> I found this quote particularly instructive:
>>>> "When Ant started to support setting properties from environment
>>>> variables it ran on Java 1.2 where System.getEnv didn't work. So we
>>>> decided to start a command in a new process which prints the
>>>> environment variables, analyzes the output and creates the properties.
>>>> Once Java 5 became our baseline we could have switched to getEnv but
>>>> it returned different results on some platforms so we stuck with the
>>>> command approach to remain backwards compatible."
>>>>
>>>> What this basically says is that at one time Java made environment
>>>> variables very hard - so people tended to avoid them in the Java world
>>>> - and used Properties instead (while the whole rest of the world, and
>>>> all other programming languages, used Environment Variables).  GoCD
>>>> uses both.  Sort of.  You will see there there are places you can set
>>>> Environment Variables in GoCD where you cannot set Properties.
>>>>
>>>> You will quickly notice how Ant uses properties is similar to how Bash
>>>> uses environment variables.  CoCD tries to use both.
>>>>
>>>> On Windows I think GoCD uses CMD.EXE - some documentation for that is
>>>> here:
>>>>
>>>> https://ss64.com/nt/cmd.html
>>>>
>>>> Once you understand Environment Variables in Bash and CMD.EXE and
>>>> understand Properties in Ant, GoCD makes more sense.
>>>>
>>>> General Note on GoCD Documentation:
>>>>
>>>> The behavior of GoCD is controlled by the XML configuration.  The Web
>>>> UI documentation assumes that you already understand the XML, so it
>>>> doesn't always explain exactly what the Web UI does.
>>>>
>>>> I have often found it helpful to read the "Configuration Reference"
>>>> for segments of the "Config XML" which are related to the GoCD Web UI
>>>> changes that I am trying to make.
>>>>
>>>> https://docs.gocd.org/current/configuration/configuration_reference.html
>>>>
>>>> Brian Fennell
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "go-cd" 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/go-cd/CAGJwi9gftjW9%3DDZnbQTsKoitEwSXxp8JHC1_RH1SakPaRT1_bw%40mail.gmail.com
>>>> .
>>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "go-cd" 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/go-cd/CAKV4bkehET%3DvU40h8xZpF3zy5vx67Zhee-fdsAM%3DZQyBdvOH1Q%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/go-cd/CAKV4bkehET%3DvU40h8xZpF3zy5vx67Zhee-fdsAM%3DZQyBdvOH1Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "go-cd" 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/go-cd/CAPKX9jbeF4J0Pg9HuW-f8eysFxtyc0N%3D7wW-pCkPDVnW4mfxfQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/go-cd/CAPKX9jbeF4J0Pg9HuW-f8eysFxtyc0N%3D7wW-pCkPDVnW4mfxfQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "go-cd" 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/go-cd/CAKV4bkeddTykAiwoVK7kOU%2B7LfVqws9rorNaNsnirihahqxShg%40mail.gmail.com
> <https://groups.google.com/d/msgid/go-cd/CAKV4bkeddTykAiwoVK7kOU%2B7LfVqws9rorNaNsnirihahqxShg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"go-cd" 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/go-cd/CANiY96bgJL9LFn%2BgQVXEmFFX3Q5vente00HQx8Z-LAoZjprxFw%40mail.gmail.com.

Reply via email to