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
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?
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:
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"
(...)
In the old build process i was appending a line at the end of every language file inside all language folders via Gulp:
gulp.src('some/folder/language/**/*.ini')
.pipe(footer('\nCONSTANT_A=\"Some Text\"'))
.pipe(gulp.dest('dest/folder/language'))
That was working good. Now i'm moving the build process to Github and trying to do that with a bash call in which i'm not that good. So this is a Git Workflow Call:
- name: Append Language Constants
run: |
for i in some/folder/language/**/*.ini
do
echo '"\nCONSTANT_A=\"Some Text\"' >> $i
done
I guess the directory masking via /**/*.ini is not possible?
I have directory
MainProject/src/
My script which I am calling test.sh run at /MainProject/ and here is some part of the sript:
dotnet restore src/*.sln
dotnet msbuild -t:publish src/*.sln -p:Configuration=Release
For this command, I want MainProject.Test as variable VAR:
dotnet vstest VAR/bin/Release/netcoreapp1.1/VAR.dll
or something like this:
dotnet vstest {src/*.Test}/bin/Release/netcoreapp1.1/{src/*Test}.dll
Which contains these files and folders:
Files:
project.sln
somescript.sh
Folders:
MainProject.Test
MainProject.Host
What I need to do is fetch MainProject.Test folder name and set it to a variable, but I also need it to be templatized where I can set it to a variable using something like *.Test
The reason for this is that I need the script parametrized because there are
MainProject2
MainProject3
MainProjectx
using the same naming convention.
The current directory is in $PWD. That's fully-qualified; to remove everything from the beginning up to the last / would be ${PWD##*/}, using a parameter expansion.
Thus, to extract the last piece of the current working directory and add .Test as a suffix:
result=${PWD##*/}.Test