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?
Related
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:
I have a yaml file that has a field data.version which I want to detect changes from main branch.\
The yaml looks something like this:
# ...
data:
version: 1.2.3
# ...
There are more fields which are not relevant for this purpose.
I am writing a GitLab-CI script where I have my current commit checked out.
I am able to see the changes in general by using this command:\
git fetch origin main
git diff origin/main HEAD -- my_yaml_file
But this does not allow me to detect changes to this specific field...
Is there a way to get and parse the original file from main branch?
Note that I am trying to avoid checking out the entire repository on a temp directory just for that purpose :)
You can get a specific version of a file with git show
git show origin/main:my_yaml_file
After that you need to parse the yaml file to get the diff
For example using yq
git show origin/main:my_yaml_file|yq eval ".data.version"
Will give out the value of data.version
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?
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