AbreQueVoy
AbreQueVoy

Reputation: 2316

Processing Gitlab variables with CLI tools

What I'm trying to do is getting user's first name to be displayed ($GITLAB_USER_NAME variable stores users' names as: Lastname, Firstname, so e.g. Jones, Indiana):

deploy_to_server:
  stage: deploy
  when: manual
  script:
    - touch report.txt
    - printf "Hello $($GITLAB_USER_NAME | awk '{ print $2 }').\n" >> report.txt
    - cat report.txt

Any clue how to process the variable with awk so that it gives the desired output, Hello Indiana?

Upvotes: 0

Views: 321

Answers (1)

AbreQueVoy
AbreQueVoy

Reputation: 2316

It turns out, in this case printf could be replaced with echo:

deploy_to_server:
  stage: deploy
  when: manual
  script:
    - touch report.txt
    - echo "Hello $GITLAB_USER_NAME" | awk '{ print $1 " " $3 ".\n\n" }' >> report.txt
    - cat report.txt

awk takes the first and the third column from the echoed string ([1]Hello [2]Jones, [3]Indiana), then I also added a space between words, and period followed by two newline characters.

In the end, the whole printout looks like this:

Hello Indiana.


Upvotes: 1

Related Questions