My question is quite simple, I'm trying to learn AzureDevOps. I have a pipeline. In this pipeline I have a task with a bash script. This task basically adds files to the archive. This archive format:
I want it to be MyPackage_09192022_MyDeploymentComment.zip
For this, I created a variable called DeploymentComment in the pipeline. When I start a queque from this pipeline, I fill in the DeploymentComment field. I added this bash script to the task as filepath, so it gives the address of the file on the machine. I also gave the $DeploymentComment variable to the arguments in this task.
My script is as follows
date="$(date +"%d%m%Y")"
zipName="MyPackage_"$date"_"$1
zip -r $zipname /home/admins/myDir/*
I am waiting for the content of the $DeploymentComment variable that I gave as an argument on the Pipeline to come to the part I specified as $1 in the script. In other words, when I start the queque, when I type my1stTry in the $DeploymentComment section, I expect the zip file created when I type my1stTry
I expect it to be MyPackage_09192022_my1stTry.zip but bash does not see this variable.
I can create a zip file as MyPackage_09192022_.zip.
What am I missing, can you help me?
This will achieve your requirements:
trigger:
- none
pool:
vmImage: ubuntu-latest
variables:
- name: DeploymentComment #Define the variable
value: MyDeploymentComment
steps:
- bash: |
xxx="$(DeploymentComment)" #Use the pipeline variable
date="$(date +"%d%m%Y")"
zipName="$(System.DefaultWorkingDirectory)/MyPackage_"$date"_"$xxx
echo $zipName
zip -r $zipName.zip ./*
ls
Successfully get the value on my side:
Related
i wanted to create pipeline that would run in every merge request, and will verify file extension. I have some old file from couple of years with language codes that are no longer used. i wanted this pipeline to find and block merge request if somehow that kind of file is there.
the proper extension would look somehow like that:
for JSON files valid filenames are *.language_code.json or *.json
for RESTEXT files valid filenames are *.language_code.restext or *.restext
List of supported language codes:
fr
ja
zh-Hans
zh-Hant
example of wrong file:
my_file.zh.json
i create gitlab-ci.yml file and wrote something like this:
image: python:3.8
stages:
- test
trigger-.zh:
rules:
- changes:
- "**/*.zh.json"
- "**/*.zh.restext"
- when: always
script:
- if ! grep "\.zh$" <(git diff --name-only HEAD~1); then exit; fi
pipeline was created and passed in next meege request, but when i tried to test it by creating "empty_file.zh.json" and commiting it, pipeline did nothing and still pass mr
What should i do differently?
I have a yaml pipeline in Azure DevOps. In one step I am using "bash" task to find a file and create a variable named "ArtifactName". The task is as follows. The issue is it cannot create the variable and the pipeline although runs successfully does not create the variable and prints: "ArtifactName: command not found."
Bash syntax in pipeline:
- bash: |
echo $(Build.SourcesDirectory)
ArtifactName=find $(Build.SourcesDirectory) -name '*.whl'
echo "Artifact name value is " $(ArtifactName)
displayName: 'Find the artifact in source directory'
workingDirectory: $(Build.SourcesDirectory)
The error message is as follows. As it is shown the variable ArtifactName is empty:
I changed the code to make sure it gets some value and see if the problem was from regular expression part but again I get the same error with this code:
- bash: |
echo $(Build.SourcesDirectory)
ArtifactName=$(find $(Build.SourcesDirectory) -name '*.whl')
echo "Artifact name value is " $(ArtifactName)
displayName: 'Find the artifact in source directory'
workingDirectory: $(Build.SourcesDirectory)
The error is like previous part "ArtifactName command not found":
Even when I hard code the value of the variable ArtifactName to a string like "foo", still the same error of "ArtifactName command not found":
- bash: |
echo $(Build.SourcesDirectory)
ArtifactName="foo"
echo "Artifact name value is " $(ArtifactName)
displayName: 'Find the artifact in source directory'
workingDirectory: $(Build.SourcesDirectory)
My last try was to use the below syntax following this link to define a variable in bash, but this one also raised the same issue that ArtifactName is again empty:
- bash: |
echo $(Build.SourcesDirectory)
echo "##vso[task.setvariable variable=ArtifactName;]foo"
echo "Artifact name value is " $(ArtifactName)
displayName: 'Find the artifact in source directory'
workingDirectory: $(Build.SourcesDirectory)
The error is exactly the same:
The question is how can I use bash task to create a variable inside it with some values that I can use in other tasks of the same and other stages.
The question is how can I use bash task to create a variable inside it with some values that I can use in other tasks of the same and other stages.
To meet your requirement, you need to use the command echo "##vso[task.setvariable variable=ArtifactName;]foo" to define the pipeline variable.
Refer to this doc: Set variables in scripts
A script in your pipeline can define a variable so that it can be consumed by one of the subsequent steps in the pipeline.Set variables in scripts
It will not work on the current task, but the updated value can be used in the next tasks.
On the other hand, the format you used to run the find command in bash script has issues.
Refer to my sample:
jobs:
- job: BuildandPublish
steps:
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo $(Build.SourcesDirectory)
find $(Build.SourcesDirectory) -name '*.yml'
ArtifactName=$(find $(Build.SourcesDirectory) -name '*.yml')
echo "Artifact name value is " $ArtifactName
echo "##vso[task.setvariable variable=ArtifactName;]$ArtifactName"
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo $(ArtifactName)
In this case, it can get the file name and can be used in the next tasks with the format: $(variablename).
Result:
I'm trying to write a playbook that will go and download the version of ombi I supply on the command line as a variable, then parse part of it so I can rename the file and keep a local copy of it. Then gunzip then untar then stop the service overwrite the existing app, then restart the service.
I've written several other playbooks but parsing this part out has me stumped.
So if say this was the URL
https://github.com/Ombi-app/Ombi/releases/download/v4.32.0/linux-x64.tar.gz
I want to extract the 4.32.0 out of that url. So my playbook run line might be something like:
ansible-playbook updateombi.yml --extra-vars "ombi_release=https://github.com/Ombi-app/Ombi/releases/download/v4.32.0/linux-x64.tar.gz"
I'm assuming I would declare a var like:
ombi_version: "{{ ombi_release | urlsplit('path') }}"
but the urlsplit is what's got me stumped. Anyone able to throw me a bone?
I'm trying to write a playbook that will go and download the version of Ombi I supply on the command line as a variable ...
To do so you could simply provide the version number only
ansible-playbook updateombi.yml --extra-vars "ombi_release=4.32.0"
and construct the URL and filename afterwards within your playbook
url: "https://github.com/Ombi-app/Ombi/releases/download/v{{ ombi_release }}/linux-x64.tar.gz"
dest: /tmp/linux-x64-v{{ ombi_release }}.tar.gz
since they don't have a variable part except the version number. By doing this there would be no need for
... then parse part of it so I can rename the file ...
My concourse task is something like this:
name: test
plan:
- get: my-repo
- task: my-task
config:
inputs:
- name: my-repo
run:
path: sh
args: [my-repo/examples/run-this.sh]
And the shell script tries to fetch a file in so manner:
CONFIG_FILE=./$name.cfg
When I run the task, concourse throws this error
my-repo/examples/run-this.sh: line xx: can't open name.cfg: no such file
The location of the run-this.sh and name.cfg file are the same. Any pointers will be appreciated!
Even though the two files share the same directory, the dot in ./name.cfg uses current working directory as a reference point - so it's the directory from which the script is called, not the directory in which the script is stored.
The best option to get this to work seems to be to add some intelligence to run-this.sh to locate the name.cfg file based on its own relative location, like this:
#!/bin/bash
SCRIPT_DIR="$(dirname $0)"
CONFIG_FILE="${SCRIPT_DIR}/name.cfg"
(...)
My program has a log file that it outputs when it completes. I'd like for that output file to be named by the date when it was run.
I've tried setting a date variable, as well as adding it in line. This post says it works in line, but I'm having no luck with that method.
My current gitlab-ci.yml
variables:
MyProjectEXE: My\Project\myproject.exe
MSBuild: C:\Path\to\my\MSBuild.exe
Solution: C:\Path\to\my\project.sln
stages:
- build
- test
build:
stage: build
script: '"%MSBuild%" "%Solution%"'
test:
stage: test
script:
- '"%MSBuild%" "%Solution%"'
- '%MyProjectEXE%" --results C:\path\to\my\results\log-$(date + \"%Y%m%d-%H%M%S\").csv
The second script under test just outputs a file named
C:\path\to\my\results\log-$(date
I've tried creating a variable that holds the date at the top, and putting it there, and I've tried just about every form of quotes around that log file name.
this could solve your problem https://gitlab.com/gitlab-org/gitlab/-/issues/22901
use CI_JOB_STARTED
'%MyProjectEXE%" --results C:\path\to\my\results\log-${CI_JOB_STARTED}.csv
or at the current time in a before statement