Structured variable replacement not working for web.config (XML) - octopus-deploy

Octopus Server 2021.1
I’m attempting to use the structured variable replacement feature to replace parts of a web.config (XML) file, but it only tries to read the read the file as Json and Yaml but not Xml. The variable is called the following: /configuration/system.webServer/rewrite/rules/rule/action/#url, where #url is the attribute of the element.
I have tried many things but cant seem to get it to treat the web.config file as an XML file - does anyone have experience getting this type of substitution to work in Octopus Deploy?
The code in the web.config looks like this:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="^api/(.*)" />
<action type="Rewrite" url="http://localhost:8053/api/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
||15:22:17 Verbose | The file at C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config does not match any known filename patterns. The file will be tried as multiple formats and will be treated as the first format that can be successfully parsed.|
|---|---|
||15:22:17 Verbose | Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config with format Json|
||15:22:17 Verbose | The file at C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config couldn't be parsed as Json: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.|
||15:22:17 Verbose | Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config with format Yaml|
||15:22:17 Info | No structures have been found that match variable names, so no structured variable replacements have been applied.|
||15:22:17 Info | Structured variable replacement succeeded on file C:\Octopus\Work\20210612032325-158854-2674\staging\Web.config with format Yaml|
||15:22:17 Verbose | The file at C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config does not match any known filename patterns. The file will be tried as multiple formats and will be treated as the first format that can be successfully parsed.|
||15:22:17 Verbose | Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config with format Json|
||15:22:17 Verbose | The file at C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config couldn't be parsed as Json: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.|
||15:22:17 Verbose | Attempting structured variable replacement on file C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config with format Yaml|
||15:22:17 Info | No structures have been found that match variable names, so no structured variable replacements have been applied.|
||15:22:17 Info | Structured variable replacement succeeded on file C:\Octopus\Work\20210612032325-158854-2674\staging\Views\Web.config with format Yaml|

This should be working based on the docs.
It could be a bug. The best action now is to email support#octopus.com with the details and full log file for diagnosis.
With .NET config files, there is an alternate pattern you can use to get the same result detailed in the docs that involves combining a config file transform and substitute variable templates in files.

Related

How to replace environment variables into a text file

I have an XML file containing a path which is different depending of my environments. I created a $ENV_PATH variable which contain the correct string. How can I parse and replace $ENV_PATH in my XML file by the value of the environment variable?
Assuming you're running on linux, you can use the sed command to do exactly what you're asking. If you have the following XML file in my_file.xml:
<example>
<my_tag>SUBSTITUTE_ME</my_tag>
</example>
You can use the following command:
sed -i 's/SUBSTITUTE_ME/$ENV_PATH/g' my_file.xml
This will result in the following file (if ENV_PATH=/dev)
<example>
<my_tag>/dev</my_tag>
</example>

How do I save a multiline string to a YAML file?

I have several YAML files that store SQL scripts in them (as multiline strings). I have a Python script that takes all of these scripts and aggregates them into a single table.
Whenever I make an update to a YAML file, it converts the SQL text to a regular string (with \n's to indicate line breaks). Is there a way to preserve the multiline formatting when I make updates to the YAML file?
For multi-line scalars, you can use blocks. The pipe symbol character | to denote the start of a block.
For example:
Data: |
Some data, here and a special character like ':'
Another line of data on a separate line
Also you can check the YAML Multiline

How to use Regex Capturing Group variable in NiFi Expression Language?

I am trying to replace a date format in all lines of text file using NiFi. The file looks like this:
ABCDE,20200619,23.8
FGHIJ,20200619,14.5
...
I am trying to do this using ReplaceText processor to change 20200619 to 2020-06-19. I've made regex expression matching the date ((20\d{6},)) and I have checked that it's working: when i write $1 TESTING, in Replacement value it works as expected (single line of file looks like ABCDE,20200619, TESTING,23.8).
The problem is when I try to use Expression Language and :substring function. This is my code in Replacement value:
${$1:substring(0, 4)}-${$1:substring(4, 6)}-${$1:substring(6, 8)}
But I get following error:
NiFi Error
It looks like the Expression Language can't access my $1 variable. How can I access my Regex Capturing Group variable inside Expression Language?
This is my processor:
NiFi Processor
I found the answer: when trying to access Regex Capturing Group inside ${...} we need to use it with apostrophes, so the code like this works:
${'$1':substring(0, 4)}-${'$1':substring(4, 6)}-${'$1':substring(6, 8)}

What can I control with YAML header options in pandoc?

Only by chance did I see an example document using the toc: true line in their YAML header options in a Markdown file to be processed by Pandoc. And the Pandoc docs didn't mention this option to control table of contents using the YAML header. Furthermore, I see somewhat arbitrary lines in example documents on the same Pandoc readme site.
Main question:
What Pandoc options are available using the YAML header?
Meta-question:
What determines the available Pandoc options that are available to set using the YAML header?
Note: my workflow is to use Markdown files (.md) and process them through Pandoc to get PDF files. It has hierarchically organized manuscript writing with math. Such as:
pandoc --standalone --smart \
--from=markdown+yaml_metadata_block \
--filter pandoc-citeproc \
my_markdown_file.md \
-o my_pdf_file.pdf
Almost everything set in the YAML metadata has only an effect through the pandoc template in use.
Pandoc templates may contain variables. For example in your HTML template, you could write:
<title>$title$</title>
These template variables can be set with the --variable KEY[=VAL] option.
However, they are also set from the document metadata, which in turn can be set either by using:
the --metadata KEY[=VAL] option,
a YAML metadata block, or
the --metadata-file option.
The --variable options inserts strings verbatim into the template, while --metadata escapes strings. Strings in YAML metadata (also when using --metadata-file) are interpreted as markdown, which you can circumvent by using pandoc markdown's generic raw attributes. For example for HTML output:
`<script>alert()</script>`{=html}
See this table for a schematic:
| | --variable | --metadata | YAML metadata and --metadata-file |
|------------------------|-------------------|-------------------|-----------------------------------|
| values can be… | strings and bools | strings and bools | also YAML objects and lists |
| strings are… | inserted verbatim | escaped | interpreted as markdown |
| accessible by filters: | no | yes | yes |
To answer your question: the template determines what fields in the YAML metadata block have an effect. To view, for example, the default latex template, use:
$ pandoc -D latex
To see some variables that are set automatically by pandoc, see the Manual. Finally, other behaviours of pandoc (such as markdown extensions, etc) can only be set as command-line options (except when using a wrapper script).
It is a rather long list that you can browse by running man pandoc in the command line and navigating to "Variables set by pandoc" section under "TEMPLATES."
The top of the list includes the following among many other options:
Variables set by pandoc
Some variables are set automatically by pandoc. These vary somewhat depending on the
output format, but include metadata fields as well as the following:
title, author, date
allow identification of basic aspects of the document. Included in PDF metadata
through LaTeX and ConTeXt. These can be set through a pandoc title block, which
allows for multiple authors, or through a YAML metadata block:
---
author:
- Aristotle
- Peter Abelard
...
subtitle
document subtitle; also used as subject in PDF metadata
abstract
document summary, included in LaTeX, ConTeXt, AsciiDoc, and Word docx
keywords
list of keywords to be included in HTML, PDF, and AsciiDoc metadata; may be
repeated as for author, above
header-includes
contents specified by -H/--include-in-header (may have multiple values)
toc non-null value if --toc/--table-of-contents was specified
toc-title
title of table of contents (works only with EPUB and docx)
include-before
contents specified by -B/--include-before-body (may have multiple values)
include-after
contents specified by -A/--include-after-body (may have multiple values)
body body of document
```
You can see the documentation of pandoc for a clue: http://pandoc.org/getting-started.html
But to know exactly where it will be used you can look for templates sources of pandoc: https://github.com/jgm/pandoc-templates
For example, for the html5 output the file is: https://github.com/jgm/pandoc-templates/blob/master/default.html5
Here's an section of the code:
<title>$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$</title>
As you can see it has title-prefix and pagetitle.
You can look the documentation, but the best solution is to look for the source code of the version you are using.
The pandoc main page now contains a list of options and explanations for them:
https://pandoc.org/MANUAL.html#variables
It seems to be the same as the one when looking at man pandoc.

ant command for block replacement

I have an HTML file containing block of code which is bounded by predefined text like
#begin#
MYcode line 1
Mycode line 2
some other code
#end#
I would like to run mvn ant command to do processing on this file such that
any text between #begin# to #end# should be replaced by multi block statment i had.
like
#begin#
This is my final code
#end#
Thanks
keshav
<replaceregexp match="#begin#;(.*?)#end#;"
replace="Any Text you want"
flags="gs">
<fileset dir="${project.build.directory}" includes="*.*"/>
Above code will do replacement of regular expression for the tokens.

Resources