title: How to use custom variables in gitlab ci/cd?
body: <p>I'm struggling with gitlab ci/cd variables. I see so many conflicting examples. Anyhow, what I would like to know is how to use variables outside and within scripts.</p>
  <p>For example, in a job config, can I assign a variable in the script section with a bash command?</p>
  <pre><code>some-job:
     variables:
        SOME_VAR: ''
     script:
        - SOME_VAR = $(&lt;file_with_a_line_of_text.txt)
  </code></pre>
  <p>In the above case, I'm not sure if I can do this. But I need to populate a variable with the file contents (i.e. artifact). Also, when do I use '$' in front of the variable? Some examples I see using these formats:</p>
  <pre><code>&quot;SOME_VAR&quot; #in quotes, no dollar sign
  &quot;${SOME_VAR}&quot; #in quotes, with dollar sign and wrapped with curly braces
  ${SOME_VAR} #no quotes, with dollar sign and wrapped with curly braces
  $SOME_VAR #i.e. without the double quotes or curly braces
  SOME_VAR #i.e. without the double quotes, dollar sign, and curly braces
  </code></pre>
  <p>So many variations of usage that I can see in examples but don't really know when to use each style. And I can't find one example online of a custom variable being set in a script using a bash command.</p>