0

I have a yaml file where I want to write a XML:

  script:
    - >
      cat > settings.xml << EOF
      <?xml version="1.0" encoding="UTF-8"?>
      <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <servers>
      <server>
      <username>$USERNAME</username>
      <password>$PASSWORD</password>
      <id>central</id>
      </server>      
      </servers>
      </settings>
      EOF

If I run the cat command in my terminal, it works but when it's executed by my pipeline, this command become a single line failing:

cat > settings.xml << EOF <?xml version="1.0" encoding="UTF-8"?> <settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <servers> <server> <username>$USER</username> <password>$PASSWORD</password> <id>central</id> </server> </servers> </settings> EOF

With the error:

parse error near `<'

Any idea how to fix this error or generate a well formated XML?

placplacboom
  • 614
  • 8
  • 16

1 Answers1

0

There are two problems:

  1. Incorrect syntax (incorrect cat > settings.xml << EOF instead of correct cat << EOF > settings.xml)

  2. The end-string EOF must be at the beginning of the line but it isn't.

To run this from the command line:

  1. Type cat << EOF > settings.xml and press ENTER.

  2. Paste (or type by hand) your XML document (without the end-string EOF) and press ENTER.

  3. Type EOF (make sure it is at the beginning of the line!) and press ENTER.

You will be presented with the command prompt. Type ls -l settings.xml to see the newly created file.

To run this from a script:

Open your text editor and follow the steps 1, 2 and 3.

Save it under the name, lets say script.sh and make it executable:

chmod 755 script.sh

Run it:

./script.sh

When the command promt is back, type ls -l settings.xml, to see the newly created file.

Aditya
  • 354
  • 2
  • 6
  • 10