You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _docs/kb/articles/check-env-vars-in-conditionals.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,13 +11,9 @@ categories: [Pipelines]
11
11
support-reviewed:2023-04-18 LG
12
12
---
13
13
14
-
##Overview
14
+
This article outlines how to execute a specific step conditionally based on the presence or absence of a variable in Codefresh pipelines, enabling branching logic within a single pipeline.
15
15
16
-
You are trying to run a specific step only if a variable is set. You are trying to have branching logic in one pipeline.
17
-
18
-
19
-
This condition determines how values are substituted for variables, when and if referenced variables do not exist in the pipeline definitions. In such cases, Codefresh retains the variable name string as-is, without substituting it with a value.
20
-
16
+
The condition determines how variable values are substituted within the pipeline's build when these variables are not defined in the pipeline configuration. In such instances, Codefresh maintains the variable name string unchanged, without replacing it with a value.
21
17
22
18
The following condition:
23
19
@@ -30,9 +26,11 @@ The following condition:
30
26
31
27
evaluates to`true` if`CF_RELEASE_TAG` does not exist, and`false` if it does exist.
32
28
33
-
##Details
29
+
##How to
34
30
35
-
1. Using the following syntax, you can check whether a variable exists for the current build:
31
+
#####Check if variable exists for the current build
32
+
33
+
Use the following syntax:
36
34
37
35
{% raw %}
38
36
@@ -45,7 +43,9 @@ evaluates to `true` if `CF_RELEASE_TAG` does not exist, and `false` if it does e
45
43
46
44
{% endraw %}
47
45
48
-
2. The following syntax can be used to check for a specific value:
46
+
#####Check if variable has a specific value
47
+
48
+
Use the following syntax:
49
49
50
50
{% raw %}
51
51
@@ -58,9 +58,9 @@ evaluates to `true` if `CF_RELEASE_TAG` does not exist, and `false` if it does e
58
58
59
59
{% endraw %}
60
60
61
-
3. If desired, you can combinemultiple checks.
61
+
Combinemultiple checks as required.
62
62
63
63
64
64
65
-
## RelatedItems
66
-
[Conditional execution of steps]({{site.baseurl}}/docs/pipelines/conditional-execution-of-steps/)
65
+
##Relatedarticles
66
+
[Conditional execution of steps]({{site.baseurl}}/docs/pipelines/conditional-execution-of-steps/)
title:"How To: Check out onlythe PR merge commit, and not the HEAD ofthe target branch"
2
+
title:"How To: Check out onlypull request merge commit for target branch instead ofHEAD"
3
3
description:
4
4
group:kb
5
5
sub-group:articles
@@ -11,22 +11,24 @@ categories: [Pipelines]
11
11
support-reviewed:2023-05-04 LG
12
12
---
13
13
14
-
##Overview
14
+
This article describes how to check out only the merge commit of a PR (Pull Request) instead of the HEAD of the target branch.
15
15
16
-
Sometimes, when you re-run a pipeline based on a PR you might find your tests that passed the first time failing the second time. This can happen because the default behavior of your pipeline is to run based on a merge of the PR and the HEAD of the target branch - so it includes the latest changes to HEAD that may not have present when the PR itself was first made.
16
+
When re-running a pipeline based on a PR, tests that passed the previous fails during the rerun.
17
+
This can happen because the default behavior of the pipeline is to run based on a merge of the PR and the HEAD of the target branch. This behavior includes the latest changes to HEAD which may not have been present when the PR itself was created.
17
18
18
19
##Details
19
20
20
-
If you want a pipelineto only runagainst the target branch asit wasat the time of thepull request, you can clone your repository using the exact SHA of the merge request.
21
+
To only run the pipeline against the target branch as at the time of thePR, clone your repository using the exact SHA of the merge request.
21
22
22
-
WhenCodefreshis triggered by aPull Request, your pipeline will haveaccess tosomeadditional variables[1]. This includesCF_PULL_REQUEST_MERGED_COMMIT_SHA, which is the commit SHA on the base branch after thepull request was merged.
23
+
Whenthe pipelineis triggered by aPR, it hasaccess to additional variablesincluding`CF_PULL_REQUEST_MERGED_COMMIT_SHA`, which is the commit SHA on the base branch after thePR was merged.
23
24
24
-
You can set up your pipeline to test and see if this variable exists[2], and depending on it's existence do two different clone steps. One clone as your existing clone if the variable is not there, or a second clone step if it is that uses CF_PULL_REQUEST_MERGED_COMMIT_SHA in the`revision` field of your clone step[3] to check out your codebase as it was at the exact moment of the PR with the PR merged into it.
25
+
Configure[conditional execution for the pipeline]({{site.baseurl}}/docs/pipelines/conditional-execution-of-steps/) to check if the`CF_PULL_REQUEST_MERGED_COMMIT_SHA` variable exists.
26
+
Depending on result, execute one of two`git-clone` steps:
27
+
* If the variable exists, specify it in the`revision` field of your`git-clone` step. This ensures that your codebase is checked out to the state it was at the precise moment the PR was merged.
28
+
* If the variable does not exist, continue with your regular clone process.
Copy file name to clipboardExpand all lines: _docs/kb/articles/clone-target-instead-of-branch-on-pr.md
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title:"How To: Clone target instead of source branchon pull request"
2
+
title:"How To: Clone target instead of source branchfor pull request"
3
3
description:
4
4
group:kb
5
5
sub-group:articles
@@ -11,19 +11,24 @@ categories: [Pipelines]
11
11
support-reviewed:2023-04-18 LG
12
12
---
13
13
14
-
##Overview
14
+
This article describes how to clone the target instead of the source branch in a PR (pull request)-triggered build.
15
15
16
-
In most cases,buildswilluse thevariable`CF_BRANCH` to referencethebranchassociated with agit triggered build.
16
+
Typically, pipelinebuilds use the`CF_BRANCH`variableto referencethe branchassociated with abuild triggeredby a Git event. However, in the case of abuild triggered by a PR,`CF_BRANCH` specifically references the source branch. To clone the_target branch_ instead of the_source branch_ during a merge, use the`CF_PULL_REQUEST_TARGET` variable, which specifically points to the target branch.
17
17
18
-
In a pull request triggered build,`CF_BRANCH` specifically refers to the
19
-
source branch, and another variable`CF_PULL_REQUEST_TARGET` refers to the
20
-
target branch. You may need to use the target branch instead in your merge
21
-
build.
22
18
23
-
##Details
24
19
25
-
* Create a separate pipeline that uses {% raw %}`${{CF_PULL_REQUEST_TARGET}}`{% endraw %} instead of the standard {% raw %}`${{CF_BRANCH}}`{% endraw %} or
26
-
* Add the following step before your clone step to check if`CF_PULL_REQUEST_TARGET` exists, and if it does assign its value to`CF_BRANCH`:
20
+
##How to
21
+
22
+
>**NOTE**
23
+
`CF_BRANCH` is available only for PR-triggered builds. Updating its value to match`CF_PULL_REQUEST_TARGET` clones the target branch instead.
24
+
If`CF_PULL_REQUEST_TARGET` is not present, the build defaults to cloning the source branch.
25
+
26
+
<!--- >>💡 The ability to override predefined variables such as `CF_BRANCH` was added recently and may be disabled for your account. If the approach described in this article does not work in your account, please [contact support](https://support.codefresh.io/hc/en-us/requests/new).-->
27
+
28
+
* Create a separate pipeline that uses {% raw %}`${{CF_PULL_REQUEST_TARGET}}`{% endraw %} instead of the standard {% raw %}`${{CF_BRANCH}}`{% endraw %}
29
+
OR
30
+
* Add the following step before your`git-clone` step to check if`CF_PULL_REQUEST_TARGET` exists.
31
+
If it does, to assign its value to`CF_BRANCH`:
27
32
28
33
{% raw %}
29
34
@@ -44,8 +49,4 @@ build.
44
49
45
50
{% endraw %}
46
51
47
-
>_Note:_
48
-
>
49
-
>`CF_BRANCH` is the source branch in a PR-initiated build. By updating its value to the value of `CF_PULL_REQUEST_TARGET` the target will be pulled instead. This variable only exists for PR triggered builds, and if not present the build will clone the source branch instead.
50
52
51
-
>💡 The ability to override predefined variables such as `CF_BRANCH` was added recently and may be disabled for your account. If the approach described in this article does not work in your account, please [contact support](https://support.codefresh.io/hc/en-us/requests/new).