Using Gitlab CI/CD to run command batch file.
I have a batch file stored locally in my system. Now I want to run it from GitLab CI/CD YAML file.
I used the below format to run the YAML
Windows:
script:
- call: ci\CheckStatus.bat init
- call: ci\CheckStatus.bat build
tags:
- windows
But it is giving me below error
Found errors in your .gitlab-ci.yml:
jobs:windows:script config should be a string or an array containing strings and arrays of strings
How to resolve this and call my batch file to execute.
There is no call keyword under script so just enter executable commands as you would use them locally:
Windows:
script:
- ci\CheckStatus.bat init
- ci\CheckStatus.bat build
tags:
- windows
Related
For example, I'm submitting a python script my_driver.py to Flink by running bin/flink run --python my_driver.py. Can I pass any user-defined arguments to my_driver.py? Or can I open and read a config file in my_driver.py
Hi i am new to docker(version 19.03.8) and basically I have an angularjs project(dummyPoject) which contains appConfig.json file with the following path dummyPoject\src\assets\conf\appConfig.json. The json file contains the following variable:
{
"baseUrl": "MAPPED-URL"
}
Basically I want to override the MAPPED-URL properties with the one that i am sending while executing docker command.
Based on the online documentation I found out that it can be passed as environment variable while running the docker command please find below:
docker run -e baseUrl=http://localhost:8081/dummyUrl/ -p 8000:8080 -d --name cms test:1.0
I was expecting that MAPPED-URL will change to http://localhost:8081/dummyUrl/ but it is not the case.
Anything I am missing here please?
By adding -e baseUrl=http://localhost:8081/dummyUrl/ to docker run you have successfully added a environment variable to your docker container. But this value will not magically replace values in your appConfig.json file.
You will need some sort of script that extracts the baseUrl variable from environment and replaces the value in the script. This could be done using a bash script which runs when the container starts and replaces the line "baseUrl": "MAPPED-URL" using the environment variable you added.
Update:
This question inspired me to create a small Node.js package command line package that should help solve your issue. The package is called replace-env
You can add replace-env to your package.json dependencies. You can then run the command as part of your Dockerfile build process, or you can have it modify the file at runtime by customizing your CMD instruction.
I have set up my gitlab project with two files: one with a batch file which just prints hello world the other file is .gitlab-ci.yml file which executes the pipeline.
The code in the batch file is:
ECHO OFF
ECHO 'Hello World'
PAUSE
The gitlab-ci.yml file has the test stage:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
When I make any changes the pipeline starts and executes successfully, but I am not getting the required output from the batch file. I am missing something here?
The pipeline result looks like this:
As I am using the gitlab-ci runner on windows I created a python script and pushed that to the self-hosted github instance. In that python script, I just triggered the .bat script which then runs and shows the output in the project pipeline.
The script looks like this:
import subprocess
subprocess.call([r'C:\hello.bat'])
That is what I wanted.
From what I see, you're only adding +x permissions to the file making it executable, but never actually running it.
If you modify your gitlab-ci.yml to:
test:
stage: test
script:
- echo 'test'
- chmod +x ./hello-world.bat
- ./hello-world.bat
That being said, I'm not 100% sure this is going to work. Since this seems to be running on a linux system, and .bat scripts are intended for windows based systems.
Please refer to bash scripts on how these work.
Trying to run gcloud init to initialize the Google App Engine Engine SDK by typing ./google-cloud-sdk/bin/gcloud init but it showed: no such file or directory or command not found. Is something wrong with my PATH? My path is:
/Users/AnneLutz/Documents/google-cloud-sdk\
If you typing ./google-cloud-sdk/bin/gcloud init and you installed Cloud SDK in /Users/AnneLutz/Documents/google-cloud-sdk, then your current directory should be /Users/AnneLutz/Documents in order for what you type to work.
That said you should add /Users/AnneLutz/Documents/google-cloud-sdk/bin to you path. To do this, assuming you are using bash you can
source /Users/AnneLutz/Documents/google-cloud-sdk/path.bash.inc
To make it so that every-time you start your shell you can add it to shell profile. For example you can add above source command at the end of ~/.bash_profile file.
It looks like you used the option to download the SDK zip file and are then trying to configure your environment with that download option. If you aren't comfortable with setting environment variables, you might want to instead try installing using the "interactive" installer, which will automate the steps for making the commands always available on your system.
The directions are here, but for Mac OS users are basically:
Enter the following at a command prompt:
curl https://sdk.cloud.google.com | bash
Restart your shell:
exec -l $SHELL
Run gcloud init to initialize the gcloud environment:
gcloud init
For many, this procedure is easier than getting everything configured manually.
Currently I have a batch file that sets all the environment variables needed before starting the build process.
It's a must to use the same bat for setting the env variables.
I tried to use EnvInject Plugin, didn't have any success.
Also tried "Execute Windows batch command" before running msbuild. e.g. start mybat.bat - this didn't seem to work either
How can I integrate the same bat file to set the variables?
Each Jenkins "build step" has it's own environment, I explained this in detail in this answer: Can not change Jenkins String Parameter Variable
If you are using the MSBuild plugin, it is its own build step, so using other build steps to change the environment is futile. If you are launching MSBuild through command line using "Execute Windows batch command", then just ran your bat file within the same build step, preceding the MSBuild command
In the case of MSBuild plugin, the only proper way is to use EnvInject plugin. Maybe you should try to figure out what isn't working for you with EnvInject plugin. From the example documentation, you want to be using "At job level" configuration, to populate your whole job with the variables from your .bat file.